Javascript - transform arrays
3 answers
Best used regex
here if there is a chance of multiple spaces in the array elements.
- Join array elements by space
- Extracting nonspatial characters from a string using a regular expression
var array = [" no yes ", " maybe certainly "];
var array2 = array.join('').match(/\S+/g);
document.write(array2);
console.log(array2);
+4
source to share