Skypanther Studios
  • Home
  • Door2Door
  • About

Delete a member of an array



Here’s a quickie: Need to delete a member of an array in JavaScript? The traditional way is with the splice() method. Here’s an alternative using filter():

var deleteFromArray = function(array, valToRemove) {
   return array.filter(function(member) {
      return member !== valToRemove;
   });
};

Demonstrated in the JavaScript console:

The filter() method examines each member of your array and applies the function you pass as its argument. In this case, our function returns the member only when it doesn’t match the value we want to remove. You could also use filter() to manipulate each array member in another way, say to multiply by some value.

JavaScript
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail
← Web site relaunch
Split window editing in TiStudio →

No Comments Yet

Leave a Reply Cancel reply

You must be logged in to post a comment.

Tweets

  • Could not connect to Twitter

Recent Posts

  • Breakpoint debugging an Alloy app
  • Titanium graphs with a WebView
  • See the Mac Console for full error details
  • Split window editing in TiStudio
  • Delete a member of an array

EvoLve Pro theme by Theme4Press  •  Powered by WordPress Skypanther Studios
Empowering a mobile world