Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to delete multiple elements of an array with splice in js

Shulou Source: shulou.com Published: 2022-05-31 10:38:05 10月08日 Update

In this article Xiaobian for you to introduce in detail "how to delete multiple elements of the array with splice in js", the content is detailed, the steps are clear, and the details are handled properly. I hope that this article "how to delete multiple elements of the array with splice in js" can help you solve your doubts.

1. Splice method

Can be used to delete, add, replace and other operations on the array of js.

Delete function: used to delete elements

2. Grammar

Array.splice (index,num)

3. Parameters

First parameter: the location of the first item to be deleted

Second parameter: number of items to delete

4. Return value

Returns a new array containing deleted items.

5. Use examples

/ / Delete var arr = [1, 2, 3, 4] Var del = arr.splice (1mem2) / / delete two elements (including those with subscript 1) console.log (arr) / / 1Power4 here, the article "how to delete multiple elements of an array with splice in js" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it before you can understand it. If you want to know more about related articles, Welcome to the industry information channel.

Tags: Elements arrays multiple parameters articles subscript location content proper two functions examples ideas new knowledge methods more steps knowledge knowledge points articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS NVidia Redmi MariaDB Shulou Technology