What is the use of splice method in JavaScript
This article will explain in detail what is the use of the splice method in JavaScript. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
Splice
Splice is the most powerful method of array in JS. It can delete, insert and replace array elements, and return the value to be operated. Shanghai Shangxue School web front-end training technical articles, pay more attention.
Splice deletion: arr.splice (1, 2) (delete items 1 and 2 in arr)
Splice insertion: arr.splice (1pink`) (insert two values before an element with an arr key of 1)
Splice substitution: arr.splice (1 and 2) (replace 1 and 2 elements in arr)
In addition, splice changes the original array. Don't be too surprised, this is exactly what splice intended.
Var x = [14,3,77]
Var y = x.splice (1,2)
Console.log (x) / / [14]
Console.log (y) / / [3,77]
This is the end of this article on "what is the use of splice method in JavaScript". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it out for more people to see.