[Javascript] 從陣列中移除物件

原文引用
http://stackoverflow.com/questions/10024866/remove-object-from-array-using-javascript

splice



//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" }]

留言

這個網誌中的熱門文章

[MySQL] schema 與資料類型優化

[翻譯] 介紹現代網路負載平衡與代理伺服器