我有这样的字符串数组:
myarray = ["第一个单词","第二个单词","更多",]
我需要从数组中删除每个第二个单词。
结果:
myarray = ["first","second","smth",]
最佳答案
您可以使用 Array.prototype.map()
var yourArray = ["first word","second word","smth more"];
var yourNewArray = yourArray.map( item => {
return item.split(' ')[0];
});
console.log(yourNewArray);
或与 Array.prototype.forEach() 大致相同
var yourArray = ["first word","second word","smth more"];
var yourNewArray = [];
yourArray.forEach( item => {
yourNewArray.push(item.split(' ')[0])
});
console.log(yourNewArray);
关于javascript - 删除部分对象js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61364484/