• Assume that we have a JavaScript array that contains a lot of objects, and the requirement here is how to remove a property of the object.
» Using map() function
let sampleArr = [
{
"id": 131,
"title": "Laravel"
},
{
"id": 134,
"title": "Django"
},
{
"id": 132,
"title": "Rail"
}
];
let newArr = sampleArr.map(item => {
const { title, ...rest } = item;
return rest;
});
Note: If you use let ids = sameplArr.map(item => item.id); and newArr = [131, 134, 132].
» Use Array.from() function
let sampleArr = [
{
"id": 131,
"title": "Laravel"
},
{
"id": 134,
"title": "Django"
},
{
"id": 132,
"title": "Rail"
}
];
let newArr = Array.from(sampleArr, ({ title, ...rest }) => rest);