[Javascript] 從陣列中移除物件
原文引用
http://stackoverflow.com/questions/10024866/remove-object-from-array-using-javascript
splice
http://stackoverflow.com/questions/10024866/remove-object-from-array-using-javascript
splice
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice
- Array.splice(index, delete_count);
//1
someArray.shift(); // first element removed
//2
someArray = someArray.slice(1); // first element removed
//3
someArray.splice(0,1); // first element removed
//4
someArray.pop(); // last element removed
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";
});
// johnRemoved = [{name:"Kristian", lines:"2,5,10"},{name:"Brian",lines:"3,9,62,36" }]
留言
張貼留言