0

I have an array of objects and want to remove all the objects that have a specific key value.

the Array looks something like this:

var myArray = [{name: "a", value: "b"}, {name: "a", value: "d"}, {name: "f", value: "r"}, {name: "g", value: "q"}];

In this case, I would like to have all objects with the name a removed form the array.

Help would be appreciated. Thanks!

0

1 Answer 1

1

Array.prototype.filter is what you are looking for, check this out for more information.

const arr = [{name: "a", value: "b"}, {name: "a", value: "d"}, {name: "f", value: "r"}, {name: "g", value: "q"}];

console.log(arr.filter((item) => {
  return item.name !== "a";
}));

Check this out for more information on Array.prototype.filter, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.