Skip to content
Advertisement

Remove Object from Array using JavaScript

How can I remove an object from an array? I wish to remove the object that includes name Kristian from someArray. For example:

JavaScript

I want to achieve:

JavaScript

Advertisement

Answer

You can use several methods to remove item(s) from an Array:

JavaScript

If you want to remove element at position x, use:

JavaScript

Or

JavaScript

Reply to the comment of @chill182: you can remove one or more elements from an array using Array.filter, or Array.splice combined with Array.findIndex (see MDN).

See this Stackblitz project or the snippet below:

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement