Given the following:
var arr = [
"one,two,three",
"four,five,six,seven",
"eight,nine,ten",
"11,12,13,14"
];
What's the best way to remove the second word from each element in the array? The desired output of the array would be:
arr = [
"one,three",
"four,six,seven",
"eight,ten",
"11,13,14"
];
I felt the most logical approach would be to use a for loop to cycle through the array and remove index 1 from each element, like as follows:
for(var i=0; i < arr.length; i++) {
i.splice(1,1).join(';');
}
(within the loop, I also tried arr[i].splice(1,1).join(';');) --- but neither approach is returning the desired outcome. What am I doing wrong and what's the most efficient way to do this?