I have array of string smth like this:
myarray = ["first word","second word","smth more",]
I need to delete each second word from array.
result:
myarray = ["first","second","smth",]
I have array of string smth like this:
myarray = ["first word","second word","smth more",]
I need to delete each second word from array.
result:
myarray = ["first","second","smth",]
You could use Array.prototype.map()
var yourArray = ["first word","second word","smth more"];
var yourNewArray = yourArray.map( item => {
return item.split(' ')[0];
});
console.log(yourNewArray);
or about the same with Array.prototype.forEach()
var yourArray = ["first word","second word","smth more"];
var yourNewArray = [];
yourArray.forEach( item => {
yourNewArray.push(item.split(' ')[0])
});
console.log(yourNewArray);