JavaScript / ๋ฌธ์ ํ์ด
๐ Today I Learned
- concat์ ํ์ฉํ ์ถ๋ ฅ ๋ฐฉ๋ฒ
- ๋ฌธ์ฅ์ ๊ฑฐ๊พธ๋ก ์ถ๋ ฅํ๊ธฐ
๋ค์ ์์ค ์ฝ๋๋ฅผ ์์ฑํ์ฌ ๋ ์ง์ ์๊ฐ์ ์ถ๋ ฅํ์์ค.
// ๋ฐ์ดํฐ
var year = '2019'
var month = '04'
var day = '26'
var hour = '11'
var minute = '34'
var second = '27'
var result = // ๋น์นธ์ ์ฑ์ฐ๊ธฐ
console.log(result);
// ์ถ๋ ฅ
2019/04/26 11:34:27
var year = '2019'
var month = '04'
var day = '26'
var hour = '11'
var minute = '34'
var second = '27'
var result = `${year}/${month}/${day} `
var result2 = `${hour}:${minute}:${second}`
var result3 = result.concat(result2)
console.log(result3)
์
๋ ฅ : ๊ฑฐ๊พธ๋ก
์ถ๋ ฅ : ๊ฑฐ๊พธ๋ก
const str = '๊ฑฐ๊พธ๋ก';
const reversed = str.split('').reverse().join('');
console.log(reversed)
--------
function getReversed(str) {
const arr = str.split('').reverse().join('');;
if (typeof str === 'string') {
return arr
}
return 'wrong type'
}
console.log(getReversed('์๋
ํ์ธ์'))