Skip to main content Accessibility Feedback

Arrays

Array.prototype.join()

Combine all items in an array into a string, separated by a delimiter that you can pass in as an argument. By default, it will use a comma (,) as the delimiter if one is not provided.

let messages = [
	'I love Cape Cod potato chips.',
	'What about you?'
];

let str = messages.join();
let strWithSpace = messages.join(' ');
let strWithSmiley = messages.join(' =) ');

// logs "I love Cape Cod potato chips.,What about you?"
console.log(str);

// logs "I love Cape Cod potato chips. What about you?"
console.log(strWithSpace);

// logs "I love Cape Cod potato chips. =) What about you?"
console.log(strWithSmiley);

Preorder my new course on Web Components! Want to learn how to build Web Components from scratch, master best practices, and more? Preorder today and get $100 off of the launch price.


Find this useful? You can support my work by purchasing an annual membership.