Below is a worked solution:
let arr = [
{ keep1: 'abc', keep2: 'def', buh1: false, buh2: false },
{ keep3: 'abc', keep4: 'def', buh3: false, buh4: true },
{ keep5: 'abc', keep6: 'def', buh5: false, buh5: false }
]
let whiteList = ['keep1', 'keep2', 'keep3', 'keep4', 'keep5'];
arr.forEach(function (obj) {
Object.keys(obj).forEach(function(key) {
if (whiteList.indexOf(key) == -1)
delete obj[key]
})
})
console.log(arr)
1
solved Javascript nested array keep only specific keys