0
Q:

js array to string

const elements = ['Fire', 'Air', 'Water'];

console.log(elements.join());
// expected output: "Fire,Air,Water"

console.log(elements.join(''));
// expected output: "FireAirWater"

console.log(elements.join('-'));
// expected output: "Fire-Air-Water"
1
var myArray = ['no','u'];
var myString = myArray.toString();
8
const arr = [1, 2, 'a', '1a'];
const str = arr.toString();
console.log(str); //> "1,2,a,1a"
5
// Defining an array with most datatypes ( objects have to be converted to string with JSON.stringify(obj) )
var myArray = ['String',"String",1,2.5, false, NaN, undefined]; 
// Convert the array into a string using the JS function toString();
var myString = myArray.toString();
// Logging it on the console
console.log(myString) // "String,String,1,2.5,false,NaN," (undefined values cannot be converted to strings)
1

const elements = ['Fire', 'Air', 'Water'];

console.log(elements.join());
// expected output: "Fire,Air,Water"

console.log(elements.join(''));
// expected output: "FireAirWater"

console.log(elements.join('-'));
// expected output: "Fire-Air-Water"
1
// array.join(separator)

var myArray ['foo', 'bar', 'baz'];
myarray.join(':');
// foo:bar:baz
0
<array>.join(<splitting character(s)>);
8
var address = "foo";
var city;
var state = "bar";
var zip;

text = [address, city, state, zip].filter(Boolean).join(", ");
console.log(text)
1

New to Communities?

Join the community