I have an array of small strings, but I received that data from outside the program, so I have no idea how the data is formatted. Most specifically, I encounter a lot of situations where I have extraneous white space before and after each string.
Problem is, I have a big array. While I could do something like this:
for (var z = 0; z < myArray.length; z++) {
myArray[z] = myArray[z].replace(/(^\s+|\s+$)/g,'');
}
or
myArray.forEach(function(part, index) {
this[index] = this[index].replace(/(^\s+|\s+$)/g,'');
}, myArray);
I'm wondering what would be a better way, or are these pretty much the best? Is there a batch function to do that?