Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use concat method and splice method in javascript array

Shulou Source: shulou.com Published: 2022-06-01 05:44:35 10月03日 Update

This article is about how to use the concat method and the splice method in javascript arrays. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

First, concat method 1 directly vs open

2 Code block / / function: merge arrays, merge one or more arrays, return the data after merging arrays without changing the original array; const geyao = ['ballad'] const fuzhu= ["very strong"] console.log (geyao.concat (fuzhu)); console.log (geyao); 3 run results

Summary:

Function: merge arrays, can merge one or more arrays, will return the data after the merged array, will not change the original array

2. Splice method 1 code part const geyao= ["ballad", "very strong", "very handsome"] / / delete 1 element from index 1 let b=geyao.splice (1p1) console.log (b, "later") console.log (geyao, "geyao1") / / from index 2 / delete 0 elements / / then insert "very strong" and "very show" geyao.splice ("very strong", "very strong") "Great") console.log (geyao, "geyao1") / / replace operation: when performing a replace operation The second parameter is the number of elements to be replaced, followed by the deleteCount elements to be replaced. Geyao.splice (2Jing 2, "very impressive", "very nice") console.log (geyao, "geyao1") 2 run result

Thank you for reading! This is the end of the article on "how to use the concat method and splice method in the javascript array". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Tags: Array method element code content function multiple data more ballad article index result run good practical awesome number parameter summary Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Docker Xiaomi vpn Apple