JQuery Array to string with toString

From CoderLearner
Jump to: navigation, search

jQuery toString

Returns string from array and uses comma to separate each array element.

Syntax

  array.toString();

Example

Convert a string to array by using the $.split() function, and use the $.toString() to convert the array elements to a string.

$(document).ready(function() {
	var myFruits='Apple Banana Coconut Mango Pear Orange';
	var myFruitsArray = myFruits.split(' ');
	alert(myFruitsArray.toString());
});

Output

Apple,Banana,Coconut,Mango,Pear,Orange