String to Array and Array to String JS

JavaScript convert string to array and array to comma separated string.

	let arr = '10 20 30 40 50';
	let newArr = arr.split(' ');
	let newArrJoin = newArr.join(',');
	
	
	console.log(arr); //input 10 20 30 40 50	
	console.log(newArr); //input ['10', '20', '30', '40', '50']
	console.log(newArrJoin); //input 10,20,30,40,50	

Leave a Reply