こんにちは私は自分が持っているオブジェクト配列からオブジェクトを削除してから、別の新しいオブジェクトを作成しようとしていました($ .map()を使用して新しいオブジェクトを作成しています)
このオブジェクトをobject(x)から削除するには、そのobject.numberは、array(y)の数値の1つと一致する必要があります。
この次のコードは機能しますが、object.number =40DEMOを持つオブジェクトのみを削除し ます
コード:
var x =[ //this is the object
{name : 'mark' , number : '10' , color:'green'},
{name : 'jeff' , number : '15' , color:'blue'} ,
{name : 'joy' , number : '30' , color:'yellow'},
{name : 'mick' , number : '15' , color:'red'},
{name : 'mick' , number : '40' , color:'black'}] ;
var y =['40','15']; // i need to remove all object.number that match the
// number in this array
var newObject = $.map(x ,function(index, value){
for(i in y){
if(index.number == y[i])
{return null ; }
else{
return index;
}
}
});
console.log(newObject);
上記のコードは、object.numberに40が含まれているオブジェクトのみを削除します。これを機能させるにはどうすればよいですか?