🔗 참고자료
MDN Array.prototype.join()
CODINGFACTORY Array.join()
WebClub 배열 메서드 join()
join()
은 배열의 원소들을 연결하여 하나의 문자열로 만들어 준다.
✨ 반환 값
arr.length
가 0
이면 빈 문자열 반환 ▶ Stringundefined
또는 null
이면 빈 문자열로 반환 ▶ String📌 예시
const lst = ['red', 'blue', 'yellow', 'green'];
// () : 원소들을 콤마(,)로 구분
// red,blue,yellow,green
console.log(lst.join());
// ('') : 원소 구분 없음
// redblueyellowgreen
console.log(lst.join(''));
// ('-') : 원소들을 -로 구분
// red-blue-yellow-green
console.log(lst.join('-'));
// ('--') : 원소들을 --로 구분
// red--blue--yellow--green
console.log(lst.join('--'));
// ('*') : 원소들을 *로 구분
// red*blue*yellow*green
console.log(lst.join('*'));