Is there a more efficient way to remove all key/value pairs from an array of objects?
For example, consider the following array:
var arr = [
{ q: "Lorem ipsum dolor sit.", c: false },
{ q: "Provident perferendis veniam similique!", c: false },
{ q: "Assumenda, commodi blanditiis deserunt?", c: true },
{ q: "Iusto, dolores ea iste.", c: false },
];
and the desired output:
var newArr = [
{ q: "Lorem ipsum dolor sit." },
{ q: "Provident perferendis veniam similique!" },
{ q: "Assumenda, commodi blanditiis deserunt?" },
{ q: "Iusto, dolores ea iste." },
];
The current solution using delete works, but is there a smarter approach?
for (var i = 0; i < arr.length; i++) {
delete arr[i].c;
};
Any suggestions would be greatly appreciated.