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

Case Analysis of Deep copy and shallow copy of slice in js

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly introduces the relevant knowledge of slice deep copy and shallow copy case analysis in js, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this js slice deep copy and shallow copy case analysis article. Let's take a look.

1. Slice shallow copy

Just copy the first-level directory, copy an array (or part of it), and not copy a deeper directory.

1. Use syntax

Array.slice ([start [, end])

2. Instructions for use

Make a shallow copy of the original array through start and end (extract array elements from start to end index)

3. Return value

Returns a shallow copy with start closed and end on.

4. Use examples

Var arr = ['Aids,' bundles, 'canals,' D']; var res = arr.slice () console.log ('arr', arr); / / [' Aids, 'breads,' cations,'D'] console.log ('res', res); / / [' Aids, 'bounds,' cations,'D']

Second, slice deep copy

For the slice function of the array object, copy all the directories of the array, make a copy of the whole, and return a section of an array (still an array), cutting off the reference relationship between the secondary and above directories.

1. Use syntax

ArrayObj.slice (start, [end])

2. Parameters

Start is required. The starting element of the part specified in arrayObj is a zero-based subscript.

End is optional. The ending element of the part specified in arrayObj is a zero-based subscript.

3. Return value

Returns an Array object that contains the specified part of the arrayObj.

4. Use examples

Let arr1 = [1, 2, 3], arr2 = arr1.slice (); arr2.pop (); console.log (arr1); console.log (arr2); this is the end of the article on "Deep copy and shallow copy instance Analysis of slice in js". Thank you for reading! I believe you all have a certain understanding of "slice deep copy and shallow copy case analysis in js". If you want to learn more, you are welcome to follow the industry information channel.

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