Created
February 21, 2014 15:49
-
-
Save shivkumarganesh/9136685 to your computer and use it in GitHub Desktop.
This code helps us to remove data from the array.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//First, find the index of the element you want to remove: | |
var array = [2, 5, 9]; | |
var index = array.indexOf(5); | |
//Then remove it with splice: | |
if (index > -1) { | |
array.splice(index, 1); | |
} | |
//The second parameter of splice is the number of elements to remove. Note, splice modifies the array in place and returns a new //array containing the elements that have been removed. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment