Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the use of splice method in JavaScript

Shulou Source: shulou.com Published: 2022-06-01 03:06:15 10月08日 Update

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.

Tags: Methods elements arrays articles articles more good practical strongest two content front end function school technology technical articles original intention knowledge in addition Shanghai Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Xiaomi MySQL Shulou Technology Microsoft