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

How to realize Array merging with js

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces js how to achieve array merging, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

1. Reduce () and reduceRight () iterate over all the items in the array and then build the final return value. Often used to accumulate array items, reduce the dimension of the array, remove the weight of the array, and count the number of occurrences.

2. The initial value of the merger is 0, and the cumulative result of each item is returned.

Example

Let arr = [[1, [2,4]], 3]; / / Array dimensionality reduction: reducefunction flattenDeep (arr) {return arr.reduce ((pre, cur) = > Array.isArray (cur)? Pre.concat (flattenDeep (cur)): pre.concat (cur), []);} let result = flattenDeep (arr); / / built-in dimensionality reduction. Flat receives a parameter, which represents dimensionality reduction several times, default reduction once, and input Infinity represents dimensionality reduction to 1-dimensional array (any infinite dimension can be reduced) arr.flat (); / / [1, [2,4], 3] arr.flat (Infinity) Thank you for reading this article carefully. I hope the article "how to merge js into arrays" shared by the editor will be helpful to everyone. At the same time, I hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you 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

Development

Wechat

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

12
Report