Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

array join() method without a separator

Tags:

javascript

var arr= ['g','o','o','d']; var arr2 = arr.join(); 

Arr2 will be "g,o,o,d". I would like to get "good". I know there are a million other ways to achieve this but was curious if there was a way with join.

like image 466
Adrian Adkison Avatar asked Jan 24 '10 03:01

Adrian Adkison


People also ask

How do you join an array without commas?

To convert an array to a string without commas, call the join() method on the array, passing it an empty string as a parameter - arr. join('') . The join method returns a string containing all array elements joined by the provided separator. Copied!

What is join method in array?

join() The join() method creates and returns a new string by concatenating all of the elements in an array (or an array-like object), separated by commas or a specified separator string. If the array has only one item, then that item will be returned without using the separator.

How do you join a split array?

How it works: First, split the title string by the space into an array by using the split() string method. Second, concatenate all elements in the result array into a string by using the join() method. Third, convert the result string to lower case by using the toLowerCase() method.

How do you join an array with spaces?

To convert an array to a string with spaces, call the join() method on the array, passing it a string containing a space as a parameter - arr. join(' ') . The join method returns a string with all array elements joined by the provided separator.


1 Answers

Sure - just pass an empty string:

var arr2 = arr.join(''); 
like image 124
Shog9 Avatar answered Oct 23 '22 13:10

Shog9