Get the App
SLTechnology News&Howtos  ›  Development  › 

Is the sort sort in es6?

Shulou Source: shulou.com Published: 2022-05-31 19:34:51 10月12日 Update

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.

Tags: Sort array knowledge articles order ascending order letters methods elements content functions parameters characters numbers coding syntax different very large from small to big two Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS OPPO Reno vpn NVidia Shulou Technology