Javascript array join Code Example

Last Updated On Thursday 20th Jan 2022

javascript array to string

  • When we use the join function.
  • If we want to join elements of an Array(set of elements).
  • Joining all Elements of the array into a string.
  • Here’s the Documentation Link

javascript join

Example 1:

	let names = ['Alice', 'Adam', 'Sam', 'Ben'];

let friends = names.join(" & ");

console.log(friends);
	

The Above Code Outputs the

	// Alice & Adam & Sam & Ben
	

Example 2:

	let meals = ['breakfast', 'dinner'];

let newMeals =  meals.join(' and ');

console.log(I Like both the ${newMeals} very much :) )
	

The Above Code Outputs the

	// I Like both the breakfast and dinner very much :)