【发布时间】:2018-10-09 02:30:55
【问题描述】:
我有如下列表项数组
L3 - LO
L7 - LO
L7 - L3
% L3 - LO
% L7 - LO
% L7 - L3
我正在尝试使用以下角度 4 中的代码使用拼接方法删除
但它也如何删除其他项目。我只想删除包含 L3 的字符串,它也删除了这个项目% L7 - LO
if (e.target.value === "L3") {
debugger;
let l7L3112Index = this.formulalist.findIndex(item => item.Name === "L7 - L3");
let l7l32456Index = this.formulalist.findIndex(item => item.Name === "% L7 - L3");
let l3ls28Idex = this.formulalist.findIndex(item => item.Name === "L3 - LS");
let l3ls23Idex = this.formulalist.findIndex(item => item.Name === "% L3 - LS");
let l3Lo87Index = this.formulalist.findIndex(item => item.Name === "L3 - LO");
let l3lO287Index = this.formulalist.findIndex(item => item.Name === "% L3 - LO");
this.formulalist.splice(l3lO287Index, 1);
this.formulalist.splice(l7L3112Index, 1);
this.formulalist.splice(l7l32456Index, 1);
this.formulalist.splice(l3ls28Idex, 1);
this.formulalist.splice(l3ls23Idex, 1);
this.formulalist.splice(l3Lo87Index, 1);
}
任何人都可以就这个问题提出任何想法。 非常感谢提前
【问题讨论】:
-
如果我理解正确,您可以使用
this.formulalist = this.formulalist.filter(i => !i.includes("L3"))删除所有包含"L3"的数组项。 -
findIndex and slice 然后 findIndex on sliced list and slice 依此类推...或以相反的顺序对索引和切片进行排序....是的,如果只需要删除 L3 那么为什么这一切?
标签: javascript arrays angular slice