Question

I have an array in Javascript and I want to change it into a variable. For example, if variable array=["a", "b", "c"] then I want variable variable to equal "abc" What's the fastest wat to do this? (My real array has almost 100 values)

Was it helpful?

Solution

I advise you to check out the documentation of arrays

The short answer is use Array.prototype.join, it takes a parameter which is the glue, the string between each elements of your array into a string.

UPDATE If you don't pass a parameter to Array.prototype.join the glue will be a comma

var array = ["a", "b", "c"];

console.log(array.join('')); // abc
// another example here
console.log(array.join('-')); // a-b-c
// and another one to show the default behaviour
console.log(array.join()); // a,b,c
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top