Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the common processing of js array

Shulou Source: shulou.com Published: 2022-06-01 05:56:17 10月01日 Update

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!

Tags: Array common processing article content method maximum valid subscript not much most object situation efficiency time more maximum knowledge coding brain Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux NVidia vpn OPPO Reno Shulou Information