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

Is the sort sort in es6?

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

Share

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

Today, I would like to share with you whether sort ranking is the relevant knowledge point in es6, the content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article.

Sort sorting is in es6; sort sorting is a method used in es6 to sort the elements of an array. This method does not pass parameters by default and sorts by character encoding order, which can be alphabetical or numeric, and in ascending or descending order. The syntax is "array.sort (callback (aMaginb)").

This tutorial operating environment: windows10 system, ECMAScript version 6. 0, Dell G3 computer.

Is the sort sort in es6?

Sort sorting is in es6

The sort () method is used to sort the elements of an array

Grammar

Array.sort (callback (aPerm b))

No parameters are passed by default and will be sorted according to the character encoding order

/ / pass parameters: the parameter is a function, and the function has two parameters (aforme b)

/ / a > b, returns a positive number

/ / a = b, 0 is returned

/ / a

< b ,返回负数,在重新排序后的数组中a位于b之前 // a - b ,返回的数组是从小到大排序的 // b - a ,返回的数组是从大到小排序的 let sortArr = [ {a:1}, {a:3}, {a:-1},]let newSortArr = sortArr.sort((r1,r2)=>

{let r = r1.amurr2.a; console.log (r) return r;})

Sort order can be alphabetical or numeric, in ascending or descending order, by default in ascending alphabetical order

As follows:

Var arr = new Array ("orange", "mango", "banana", "sugar"); var sorted = arr.sort (); console.log ("Returned string is:" + sorted); these are all the contents of the article "is sort ranking in es6?" Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to 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