JavaScript 数组删除的几种方式
ZKEASOFT September 29, 2017
按索引删除
//1 someArray.shift(); // 删除第一个元素 //2 someArray = someArray.slice(1); // 删除第一个元素 //3 someArray.splice(0,1); // 删除第一个元素 //4 someArray.pop(); // 删除最后一个元素
按条件删除
someArray = [{name:"Kristian", lines:"2,5,10"}, {name:"John", lines:"1,19,26,96"}, {name:"Brian",lines:"3,9,62,36" }]; johnRemoved = someArray.filter(function(el) { return el.name !== "John"; }); console.log(JSON.stringify(johnRemoved, null, ' '));