Array Method collation

Source: Internet
Author: User
Tags array sort

 var arrcompate = function () {var json = {}, result = [];            return {//Max Max:function (arr) {return Math.max.apply (Math, arr);            },//Minimum value min:function (arr) {return Math.min.apply (Math, arr);                },//Go to repeat unique:function (arr) {var json = {}, result = [];                Console.log (); for (var i = 0, len = arr.length; i < Len; i++) {if (!json[arr[i]]) {Json[a                        Rr[i]] = arr[i];                    Result.push (Arr[i]);            }} return result; },//Ascending sort sort:function (arr) {return Arr.sort (function (A, b) {R                Eturn A-B;            }); },//Descending sort descen:function (arr) {return Arr.sort (functiOn (A, B) {return b-a;            });                    },//array scrambled Order Reset:function (arr) {return Arr.sort (function (A, b) {                Return Math.random ()-0.5;            });  },//object array sort, roughly similar to above, write-only ascending objsort:function (arr,name) {return Arr.sort (function (A, B)                {return a[name]-b[name];            });    },}} var arry = [1, 2, 3, 4, 5, 2, 3, 4];    var obj=[{num:1,text: ' 1 '},{num:3,text: ' 1 '},{num:2,text: ' 1 '}];    var resu = Arrcompate (). Objsort (obj, ' num '); Console.log (ResU)

<!--code reference from http://luckykun.com/work/2016-10-11/com-func-skill.html to

  

Array Method collation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.