javascript / beginner
Snippet
Joining Array Elements into a String
The .join() method creates and returns a new string by concatenating all elements in an array, separated by a specified separator string.
snippet.js
javascript
1
2
3
const fruits = ['Apple', 'Banana', 'Cherry'];const fruitList = fruits.join(', ');console.log(fruitList); // Output: "Apple, Banana, Cherry"
react
Breakdown
1
const fruits = [...];
An array containing three string elements is declared.
2
fruits.join(', ');
Combines the array items into one string, placing a comma and space between each.