findIndex
es6语法,对ie11 不兼容
当数组中的元素在测试条件时返回 true 时, findIndex() 返回符合条件的元素的索引位置,之后的值不会再调用执行函数。
deleteData: function (id) {
//此处的this指代实例
let index = this.list.findIndex(function (e) {
//此处的this指代window
return e.id == id
});
this.list.splice(index, 1);
},
some
如果有一个元素满足条件,则表达式返回true , 剩余的元素不会再执行检测。没有兼容性问题
deleteData: function (id) {
var _this = this;
//此处的this指代实例
this.list.some(function (e,index) {
if (e.id == id) {
//此处的this指代window
_this.list.splice(index, 1);
return true;
}
});
},