Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use slice method and join ​​ method in javascript array

Shulou Source: shulou.com Published: 2022-06-01 05:44:11 09月30日 Update

Xiaobian to share with you how to use the slice method and join method in javascript array, I believe most people do not know how to use it, so share this article for your reference, I hope you have a lot of harvest after reading this article, let's go to understand it together!

1. slice method 1 editor section

2 Code parts map const geyao=["geyao","geyao1","geyao2"]//Required. Specify where to start selecting. If negative, it specifies the position from the end of the array. That is,//-1 refers to the last element,-2 refers to the penultimate element, and so on.// Optional. Specify where the selection ends. This parameter is the array index at the end of the array fragment. If this parameter is not specified,//then the split array contains all elements from start to end of the array. If this argument is negative, then it specifies elements counting from the end of the array.// The first is the start index and the second is the end index//(leaving the original array unchanged) let geyao1=geyao.slice(1,3) console.log(geyao,"later") console.log(geyao1,"later") //where to start let geyao2=geyao.slice(1) console.log(geyao,"later") console.log(geyao1,"later")3 Run results

Summary:

Required. Specify where to start selecting. If negative, it specifies the position from the end of the array. That is,-1 refers to the last element,-2 refers to the penultimate element, and so on. Optional. Specify where the selection ends. This parameter is the array index at the end of the array fragment. If this parameter is not specified, the partitioned array contains all elements from the start to the end of the array. If this argument is negative, then it specifies elements counting from the end of the array. The first is the start index and the second is the end index (leaving the original array unchanged).

2. Join Method 1 Editor

2 Code parts var elements ="'ballad ','very strong',' excellent'"]; console.log (elements.join()); console.log (elements.join ('')); console.log (elements.join ('-'));3 Run results

The above is " javascript array slice method and join method how to use" all the content of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!

Tags: Array element method parameter tail index negative position article part primitive and so on subscript that is code content fragment result editor Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Huawei Shulou Tech Info Redmi OPPO Reno