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

What is the common processing of js array

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

Editor to share with you what common js array processing, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!

Common array processing

Master the common methods of array, keep them in mind, don't read API while writing, this can effectively improve the coding efficiency, after all, these methods are used every day.

Every some filter map forEach find findIndex reduce includes

Const arr = [1Jing 2jue 3] / / every each item is valid before trueconsole.log (arr.every (it = > it > 0)) / / true//some is returned. It returns trueconsole.log (arr.some (it= > it > 2)) / / true//filter filter console.log (arr.filter (it= > it===2)) / / [2] / / map returns a new array console.log (arr.map (it= > it=== {id:it})) / / [{id:1}, {id:2} {id:3}] / / forEach does not return a value console.log (arr.forEach (it= > it===console.log (it)) / / undefined//find lookup corresponding value returns the new array console.log (arr.find (it= > it===it > 2)) / / 3//findIndex looks up the corresponding value and returns the subscript console.log (arr.findIndex (it= > it===it > 2) of the new array immediately after finding the corresponding value. / / 2//reduce summation or merge array console.log (arr.reduce ((prev) Cur) = > prev+cur)) / / 6//includes summation or merging array console.log (arr.includes (1)) / / true// array deduplicates const arr1 = [1mine2jing3jing3] const removeRepeat = (arr) = > [. New Set (arr1)] / / [1mai2 3] / / find the maximum value of Math.max (... arr) / / 3Math.min (... arr) / / 1 arr / object deconstruction in this case, you can also use Object.assign instead of let defaultParams= {pageSize:1, sort:1} / / goods1let reqParams= {... defaultParams, sort:2} / / goods2Object.assign (defaultParams, {sort:2}). These are all the contents of the article "what is the common handling of js arrays?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, 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

Development

Wechat

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

12
Report