Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Will the concat of js change the original array?

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

The main content of this article is to explain "whether the concat of js will change the original array". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "will the concat of js change the original array"?

In the JavaScript array, the concat method can be used to join multiple arrays to form a new array, and we do not want to change the original array when joining, so will the concat method change the original array? The answer is no change. When you use the concat method, the members of the new array are added to the end of the original array, and then a new array is returned. The original array is not changed, even if other types of values are passed in, they are added to the end of the array as new elements, and the original array is also not changed.

1. Concat method

You can add array elements or merge two arrays

Only one copy of the joined array will be returned, but the original array will not be changed

Second, parameters

Parameter can be array,string,number,object

The order of each parameter is the element of the parameter (if the parameter is an array) or the parameter itself (if the parameter is not an array).

It is not recursive into nested array parameters.

III. Remarks on concat ()

1. If the parameter is an array type (Array), all the elements in the parameter array are concatenated to the end of the current array in turn; if it is of another type, add itself as an element to the end of the current array.

2. This method does not change the existing array, but only returns a copy of the joined array.

4. Return value

Returns a new array, and if an array is passed as an argument to the concat () method, the elements in the array are added instead of the array itself.

V. examples

Var a = [1Jing 2jue 3]; [xss_clean] (a.concat (4Jing 5))

Output

I believe that the "js concat will change the original array" has a deeper understanding, might as well come to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report