DEV Community

Shubham Jadhav
Shubham Jadhav

Posted on

5 1

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
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...

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (1)

Collapse
 
naiche_young profile image
Naiche Young β€’

Good explanation!
Thanks

The best way to debug slow web pages cover image

The best way to debug slow web pages

Tools like Page Speed Insights and Google Lighthouse are great for providing advice for front end performance issues. But what these tools can’t do, is evaluate performance across your entire stack of distributed services and applications.

Watch video

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay