2017-12-01 18 views
0

と削除したいLodash、uuid:xxxでxxx2ではないオブジェクト。Lodashでオブジェクトを削除する方法(検索と削除)

どうすればいいですか?Lodash

私の実際のコード
[ 
    { 
     "uuid": "xxx", 
     "name": "test" 
    }, 
    { 
     "uuid": "xxx2", 
     "name": "test 2" 
    } 
] 

_.forEach(this.objs, (obj, index, collection) => { 
    _.remove(obj, {uuid}) 
}) 
+0

あなたは 'ARR = arr.filter(({UUID})=> UUID == 'XXX'!)フィルタを使用することができ、アレイ内の[取り外し要素の' –

+0

可能重複Lodashを使用する](https://stackoverflow.com/questions/28036716/removing-elements-in-an-array-using-lodash) –

+0

新しい配列または_.removeを返す_.filterがあり、それを変更します。 –

答えて

1

ためArray.prototype.filter()を使用することができます。

var objects = [ 
 
    { 
 
     "uuid": "xxx", 
 
     "name": "test" 
 
    }, 
 
    { 
 
     "uuid": "xxx2", 
 
     "name": "test 2" 
 
    } 
 
]; 
 

 
_.remove(objects, o => o.uuid === 'xxx2'); 
 

 
console.log(objects);
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lodash.min.js"></script>

+0

'_.remove(objects、{uuid: 'xxx2'}); ' –

+0

Doesn –

+0

@CélineMartin私の答えで 'Run code snippet'ボタンを押してください。または私にあなたの期待された出力を与えるか? –

0

あなたは_.remove方法簡単な使用をできること

let arr = [ 
 
    { 
 
     "uuid": "xxx", 
 
     "name": "test" 
 
    }, 
 
    { 
 
     "uuid": "xxx2", 
 
     "name": "test 2" 
 
    } 
 
] 
 

 

 
arr = arr.filter(e => e.uuid != 'xxx2'); 
 

 
console.log(arr);

関連する問題