우리는 리터럴의 중첩된 배열을 취하고 그 안에 있는 모든 값을 문자열에 연결하여 문자열로 변환하는 JavaScript 함수를 작성해야 합니다.
const arr = [ 'hello', [ 'world', 'how', [ 'are', 'you', [ 'without', 'me' ] ] ] ];
예시
다음이 중첩된 배열이라고 가정해 보겠습니다. -
const arr = [
'hello', [
'world', 'how', [
'are', 'you', [
'without', 'me'
]
]
]
];
const arrayToString = (arr) => {
let str = '';
for(let i = 0; i < arr.length; i++){
if(Array.isArray(arr[i])){
str += arrayToString(arr[i]);
}else{
str += arr[i];
};
};
return str;
};
console.log(arrayToString(arr)); 출력
다음은 콘솔의 출력입니다 -
helloworldhowareyouwithoutme