Want to trim each string in an array, e.g., given
x = [\' aa \', \' bb \'];
output
[\'aa\', \'bb\']
My fi
var x = [" aa ", " bb "];
console.log(x); // => [" aa ", " bb "]
// remove whitespaces from both sides of each value in the array
x.forEach(function(value, index){
x[index] = value.trim();
});
console.log(x); // => ["aa", "bb"]
All major browsers support forEach()
, but note that IE
supports it only beginning from version 9.