Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using join method in nested array

i have this nested array arr:

[[ "one", "two" , "three"]] I want to extract the values and join them in a var called numbers and separate them by ";"

I used this method :

var itemsArray = arr.join(";");

what i a getting is this :

one,two,three

Although what i am aiming for is one;two;three

It's reading the separator.

like image 314
yasser h Avatar asked Jul 05 '26 19:07

yasser h


1 Answers

if the array is nested and number of levels are only two, then try

var arr = [[ "one", "two" , "three"]];
var itemsArray = arr.map( function( item ){ return item.join( ";" )  } ).join(";");

console.log( itemsArray );
like image 91
gurvinder372 Avatar answered Jul 08 '26 10:07

gurvinder372



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!