An Interest In:
Web News this Week
- April 1, 2024
- March 31, 2024
- March 30, 2024
- March 29, 2024
- March 28, 2024
- March 27, 2024
- March 26, 2024
Array.splice() method in JavaScript
Array.splice() method in JavaScript.
What is splice method?
=> The splice array method removes array items and replace it if any items provided.
Syntax of splice method
=> arrayName.splice(starting index of item to remove, number of items to remove, replace item)
The third parameter is optional in splice method.
=> Examples of splice method
=> Explanation :-
In the above example I created an array which name is arr and store some values [1,2,3,4,5].
Now I use splice method and I am passing two parameters, first parameter is 2 and second parameter is also 2.
The first parameter indicate that index number of array items and second parameter indicate that how many items to remove.
Then, I stored splice method in another variable name is splice_arr.
The output is [3,4].
Stay tuned with us for more
JavaScript method articles
Thank you for reading...
Original Link: https://dev.to/dev_shubham/array-splice-method-in-javascript-4mnm
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To