Remove value from an Object in JavaScript
我有如下代码。我想把
1 2 3 4 5 6 7 8 | _self.verses.filter(verse => { Object.keys(verse).forEach(function(key) { if(! _self.recieved_translation.includes(key)) { // I would like to remove this verse from verses } }); }); |
1 2 3 4 5 6 7 8 | _self.verses.filter(verse => { Object.keys(verse).forEach(function(key) { if(! _self.recieved_translation.includes(key)) { delete verses[verses]; } }); }); |
1 2 3 4 5 6 7 8 | _self.verses = _self.verses.filter(verse => { // We don't need foreach here, we just need the first key var keyWithoutTranslation = Object.keys(verse).find(function(key) { return !_self.recieved_translation.includes(key); }); // Now the filter will do the rest return keyWithoutTranslation === undefined; }); |
1 | _self.verses.forEach(verse => delete verse.verse); |
使用