Ways to remove an Element from Array
JavaScript arrays allow you to group values and iterate over them. You can add and remove array elements in different ways. Unfortunately, there is not a simple Array.remove method. Here are some ways to remove an element from the array
- pop
- shift
- splice
- remove the specific element with splice
1. pop
The pop() method removes the last element of an array, and returns that element.
2. shift
The shift() method removes the first item of an array. The shift() method changes the original array.
3. splice
The splice() method adds/removes items to/from an array, and returns the removed item(s). Splice also changes the original array.
0 Response to "Ways to remove an Element from Array"
Post a Comment