SW κ°λ°/Vanilla JS
[JavaScript] λ°°μ΄ λ³ν© ν¨μμ λν΄ μμ보μ!(concat, join)
DATA101
2021. 12. 1. 13:14
728x90
λ°μν
π‘ λͺ©ν
JavaScriptμμ λ°°μ΄μ μμ μΆκ°/μμ νλ λ°©λ²μ λν΄ μ΄ν΄νλ€.
λ€μ΄κ°λ©°
λ°°μ΄ μ μΈ
const arr = [80, 20, 10, 99, 1234];
μμ κ°μ΄ λ°°μ΄ κ°μ²΄λ₯Ό μμ±νλ λμμ μ΄κΈ°ννμ΅λλ€.
1. concat ν¨μ: λ°°μ΄ κ° λ³ν©
let arrConcat = arr.concat(5678);
console.log("arr: ", arr); // [ 80, 20, 10, 99, 1234 ]
console.log("arrConcat: ", arrConcat); // [ 80, 20, 10, 99, 1234, 5678 ]
consoloe.log('----------------------------');
arrConcat = arr.concat([111, 222]);
console.log("arr: ", arr); // [ 80, 20, 10, 99, 1234 ]
console.log("arrConcat: ", arrConcat); // // [ 80, 20, 10, 99, 1234, 111, 222 ]
concat ν¨μλ κΈ°μ‘΄ λ°°μ΄μ λ¨μΌ μμ λλ λ°°μ΄μ λ³ν©νμ¬ λ°νν©λλ€.
2. join ν¨μ: λ°°μ΄ λ΄ μμ κ° λ³ν©
let arrJoin = ['A', 'B', 'C'];
console.log(arrJoin.join()); // A,B,C
console.log(arrJoin.join('+')); // A+B+C
console.log(arrJoin.join('')); // ABC
join ν¨μλ λ°°μ΄ λ΄ μμ κ° λ³ν©ν©λλ€. λ§€κ°λ³μλ ꡬλΆμ μν μ ν©λλ€.
λ§€κ°λ³μκ° μλ€λ©΄ κΈ°λ³Έκ°μΌλ‘ μ½€λ§κ° ꡬλΆμκ° λλ©°,
'+'λ₯Ό μ λ¬νλ©΄ μμ κ° λ³ν© μ +κ° κ΅¬λΆμκ° λ©λλ€.
ν¬μ€ν λ΄μ©μ μ€λ₯κ° μλ€λ©΄ μλμ λκΈ λ¨κ²¨μ£ΌμΈμ!
κ·ΈλΌ μ€λλ μ¦κ²κ³ 건κ°ν ν루 보λ΄μκΈΈ λ°λλλ€.
κ³ λ§μ΅λλ€ :-)
728x90
λ°μν