xxxxxxxxxx
const arr = [
{id: 1, name: 'user1', test: 'abc'},
{id: 2, name: 'user2', test: 'xyz'},
];
//----------------REMOVE test KEY-----------------------------
const newArr = arr.map(({test, rest}) => {
return rest;
});
//---------------------------------------------
console.log(newArr)
/******
[{ id: 1, name: 'user1' },{ id: 2, name: 'user2' }]
******/
xxxxxxxxxx
let _array=[{id:0:name:"Hello 0"},{id:1:name:"Hello 1"},{id:2:name:"Hello 2"}]
const removeArrayObject = function (arr, attr, value) {
// parameters : arr= Array, attr=Object key, value=Object Object key value
var i = arr.length;
while (i--) {
if (arr[i] && arr[i].hasOwnProperty(attr) && arr[i][attr] === value) {
arr.splice(i, 1);
}
}
return arr;
}
console.log(removeArrayObject(_array, "id", 1))
// result = [{id:0:name:"Hello 0"},{id:2:name:"Hello 2"}]