Skip to content
Advertisement

Is there a way to combine all elements in an array?

So I’m making a website, and I want to string together all the items in an array. e.g:

function combineArray {
const myArray = [text1, text2, text3];
//code to output text1text2text3 here
}

Does anyone know how to do this?

Advertisement

Answer

join will join all elements in the array with the specified delimiter (use empty string '' since the default separator is comma ,)

const myArray = ["a", "b", "c"];
const res = myArray.join('');
console.log(res);
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement