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…


This content originally appeared on DEV Community and was authored by Shubham Jadhav

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
example 1
=> 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].

=> Another example :-
Example 2

? Stay tuned with us for more
JavaScript method articles
? Thank you for reading...


This content originally appeared on DEV Community and was authored by Shubham Jadhav


Print Share Comment Cite Upload Translate Updates
APA

Shubham Jadhav | Sciencx (2021-09-11T04:58:29+00:00) Array.splice() method in JavaScript ?. Retrieved from https://www.scien.cx/2021/09/11/array-splice-method-in-javascript-%f0%9f%9a%80/

MLA
" » Array.splice() method in JavaScript ?." Shubham Jadhav | Sciencx - Saturday September 11, 2021, https://www.scien.cx/2021/09/11/array-splice-method-in-javascript-%f0%9f%9a%80/
HARVARD
Shubham Jadhav | Sciencx Saturday September 11, 2021 » Array.splice() method in JavaScript ?., viewed ,<https://www.scien.cx/2021/09/11/array-splice-method-in-javascript-%f0%9f%9a%80/>
VANCOUVER
Shubham Jadhav | Sciencx - » Array.splice() method in JavaScript ?. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/09/11/array-splice-method-in-javascript-%f0%9f%9a%80/
CHICAGO
" » Array.splice() method in JavaScript ?." Shubham Jadhav | Sciencx - Accessed . https://www.scien.cx/2021/09/11/array-splice-method-in-javascript-%f0%9f%9a%80/
IEEE
" » Array.splice() method in JavaScript ?." Shubham Jadhav | Sciencx [Online]. Available: https://www.scien.cx/2021/09/11/array-splice-method-in-javascript-%f0%9f%9a%80/. [Accessed: ]
rf:citation
» Array.splice() method in JavaScript ? | Shubham Jadhav | Sciencx | https://www.scien.cx/2021/09/11/array-splice-method-in-javascript-%f0%9f%9a%80/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.