Correct use of splice() in Javascript

autoload
Release: 2021-04-12 11:21:04
Original
1908 people have browsed it

Correct use of splice() in Javascript

1.splice() syntax

arrayObject.splice(index,deleteCount,item1,.....,itemX)
Copy after login
  • ##index: Specify the starting position of modification (counting from 0)

  • deleteCount: Indicates the number of array elements to be deleted.

  • item1,...,itemX: The elements to be added to the array start from theindexposition. If not specified,splice()will only remove array elements.

Return value: an array composed of the deleted elements. If only one element was removed, an array containing only one element is returned. If no elements were removed, an empty array is returned.

2. Usage example

Deleting array elements:


Copy after login

Adding new array elements:


Copy after login

Deleting array elements:

Copy after login
Recommended: "

2021 js interview questions and answers (large summary)"

The above is the detailed content of Correct use of splice() in Javascript. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!