How does javascript delete specific values in an array?

question: data format to be deleted

[
{index: 1, a: "1", b: "2", c: "3", d: "4"},
{index: 2, a: "4", b: "5", c: "6", d: "7"}
]

requirement: delete the entire data item with an index of 1. Finally leave

[
{index: 2, a: "4", b: "5", c: "6", d: "7"}
]
Apr.20,2021

can't you just drop that index on Filter

?
var arr = [{index: 1, a: "1", b: "2", c: "3", d: "4"},{index: 2, a: "4", b: "5", c: "6", d: "7"}];
var result = arr.filter(o=>o.index != 1);
console.log(result);

will this question be stepped on?
first find the index of index=1 , and then splice delete

const arr = [
  {index: 1, a: "1", b: "2", c: "3", d: "4"},
  {index: 2, a: "4", b: "5", c: "6", d: "7"}
];

const index = arr.findIndex(({index}) => 1 === index);
arr.splice(index , 1);
console.log(arr);

shouldn't we look up index, first and then delete the index

Menu