Map and Slice–A good match

8. August 2016 10:50

Ever need to remove an object from an array (in JavaScript)? In the past I’ve done things like loop through the array check each item to see if a property matches a search condition and then try to remove it. Map to the rescue!

 

       
image

 

The magic of the map function is in returning an array of just the property you are searching on. Then its simply a matter of indexOf on that array to find the index to splice out!

 

Fiddle

About the author

I'm a .NET developer, a husband and a father of three beautiful girls.

Month List