あなたは、元の配列に変更を加えることができ、次のいずれか
var a = [{name:'tc_001'}, {name:'tc_002'}, {name:'tc_003'}]
a = a.filter(function (e) {
return e.name === 'tc_001';
});
a.splice(0,1);
したり、独自のコードでは、ちょうどあなたがb
a = b
に行ってきたa
すべて[編集]に適用されます
おそらく、私がそれぞれの行動が何をしているのかを明らかにすれば、より明確になるでしょう。
var a = [{name:'tc_001'}, {name:'tc_002'}, {name:'tc_003'}]
// You now have array a with 3 elements.
b = a.filter(function (e) {
return e.name === 'tc_001';
});
// a is still 3 elements, b has one element (tc_001)
b.splice(0,1);
// You remove the first element from b, so b is now empty.
あなたは要素を削除tc_002
とtc_003
a
からではなく、b
でそれらを保持する場合、これはあなたが何ができるかです:
var a = [{name:'tc_001'}, {name:'tc_002'}, {name:'tc_003'}]
b = a.filter(function (e) {
return e.name != 'tc_001';
});
a = a.filter(function(item) { return b.indexOf(item) == -1; });
console.log(a); // tc_001
console.log(b); // tc_002, tc_003
Array.prototype.filter()の代わりになるものは何ですか?(http://stackoverflow.com/q/37318808/1447675) –
次のa.splice(0、 1)。 –