【发布时间】:2020-03-17 03:47:30
【问题描述】:
我需要在数组中有一个对象的索引,这样我才能删除数组的这一部分。我试过用这个:
var index = this.urenRegistratie.indexOf(newDatum);
但它一直返回-1,我不知道为什么会这样。
这是我拥有的代码的一部分。它从 html 中的表单中获取数据并将其放入我的数组中,现在我已经准备好一个 if 语句(exisitingDatum),我的代码需要在那里。有人可以帮帮我吗?
store(newValue:number, newDatum, newAanwezig, newComment){
const existingDatum = this.urenRegistratie.find(billable => {
return billable.datum === newDatum;
return
});
if (!existingDatum) {
let billable = new BillableHours();
billable.datum = newDatum;
billable.hours = +newValue;
billable.aanwezig = newAanwezig;
billable.comment = newComment;
if(billable.aanwezig == "Aanwezig" && billable.hours !== 0 && billable.datum !== null) {
this.urenRegistratie.push(billable);
}
}
if(existingDatum) {
}
}
【问题讨论】:
标签: javascript arrays angular typescript indexof