How To Join Array Of Strings In Javascript
I want to join an array of result = ['July',' ','1st'] into result = ['July 1st']. I also want to have the comma removed. I have tried result.join() and result.join(',') but it di
Solution 1:
You just need to join it and put into an array...:
result = [result.join('')];
Solution 2:
You need to specify empty string in .join
function
var result = ["July"," ","1st"]
result.join('') // "July 1st"
EDIT: and if you need output in array then it will
[result.join('')] // ["July 1st"]
Solution 3:
var b ="";
result.forEach(function(a){b = b.concat(a);});
console.log(b);
Solution 4:
You can also use the javascript reduce() function as follows:
var result = [result.reduce(function(previousString, currentString) {
return previousString + currentString
})];
For a more detailed explanation of how it works, check out this video by Mattias Petter Johansson
Post a Comment for "How To Join Array Of Strings In Javascript"