0

如何從使用javascript的多維關聯數組中刪除數組?

[{"email":"[email protected]","pass":"[email protected]","name":"akhil","car1":"zen","year1":"2012","member":"no","mobile":"(903) 309-8713"},{"email":"[email protected]","pass":"[email protected]","name":"suresh","car1":"zen","year1":"2012","member":"yes","mobile":"(903) 309-8799"},{"email":"[email protected]","[email protected]":"[email protected]","name":"rakesh","car1":"zen","year1":"2012","member":"no","mobile":"(903) 309-2233"},{"name":"akhil","email":"[email protected]","pass":"[email protected]","mobile":"(903) 309-8713","car1":"zen","car2":"","year1":"2012","year2":"","member":"yes"},{"name":"karan","email":"[email protected]","pass":"[email protected]","mobile":"(903) 309-2233","car1":"zen","car2":"","year1":"2012","year2":"","member":"yes"}]

這是我的數組,i灣刪除包含電子郵件ID = [email protected]這樣,我怎麼能刪除陣列?

+0

是簡單的數組,這是多維關聯數組...這兩個問題之間的區別很多我 –

+0

試過,但未能找到解決辦法 –

+0

刪除和拼接功能我想 –

回答

0

我建議使用Array#filter()並將結果分配給想要的變量。

var array = [{ "email": "[email protected]", "pass": "[email protected]", "name": "akhil", "car1": "zen", "year1": "2012", "member": "no", "mobile": "(903) 309-8713" }, { "email": "[email protected]", "pass": "[email protected]", "name": "suresh", "car1": "zen", "year1": "2012", "member": "yes", "mobile": "(903) 309-8799" }, { "email": "[email protected]", "[email protected]": "[email protected]", "name": "rakesh", "car1": "zen", "year1": "2012", "member": "no", "mobile": "(903) 309-2233" }, { "name": "akhil", "email": "[email protected]", "pass": "[email protected]", "mobile": "(903) 309-8713", "car1": "zen", "car2": "", "year1": "2012", "year2": "", "member": "yes" }, { "name": "karan", "email": "[email protected]", "pass": "[email protected]", "mobile": "(903) 309-2233", "car1": "zen", "car2": "", "year1": "2012", "year2": "", "member": "yes" }]; 
 

 
array = array.filter(function (a) { 
 
    return a.email !== '[email protected]'; 
 
}); 
 

 
document.write('<pre>' + JSON.stringify(array, 0, 4) + '</pre>');

+0

有什麼你通過stringify參數? –

+0

對象,替代品和間隔符,根據https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify –

+0

Thanx alot @ nina-scholz –