Generation

generate functionThu, 01 Dec 2022

delete attribute from object inside an object array filtering by another attribute

let data = [ { name: "user", age: 99, coins: 5 }, { name: "user2", age: 99, coins: 5 } ]; function deleteProp(arr, prop, condition) { return arr.map(obj => { const copy = { ...obj }; if (obj[prop] === condition) { delete copy[prop]; } return copy; }); } console.log(deleteProp(data, "coins", 5));

Javascript
Generate More

Want to kickstart your project?Use the new AI Studio to create your code