1. Array de-weight/*method One: 1, ' 1 ' will be considered the same; all hash objects, such as {x;1},{y:1}, will be considered the same//10ms*/Array.prototype.unique=function(){ varnewarr=[],obj={}; for(vari=0,len= This. length;i){
Php basic knowledge Summary (1) array, basic knowledge array
I. Sorting1. asort-Positive Sorting to maintain the index relationship2. arsort-reverse sorting to maintain the index relationship3. sort -- sorting from the lowest to the highest4. ksort -
first, an array of related operations1. Definition(1) var arr=[1, ' abc ', function () {alert (3333);},[333,444]]; (2) var arr=new Array (12,5,8,9); If you put only one number, set the length (3) [] to a slightly higher performance because the
Preface
A very common requirement for sorting an array. Especially at the back end. Of course, the front end also has this demand.
Of course, array ordering is a ready-made method. The sort () method.
Let's take a look at this first. Standard
var sortby = function (filed, rev, primer) {Rev = (rev)? -1:1;return function (A, b) {A = a[filed];b = b[filed];if (typeof (primer)! = ' undefined ') {A = Primer (a);b = Primer (b);}if (a if (a > B) {return Rev * 1;}return 1;}};var obj = [{b: ' 3 ',
First, we introduce the sort () method built in JS.
By default, this method sorts the elements in an alphabetical array, more precisely, by the order of character encoding.
See the following example:
When an element in an array is a numeric
ObjectiveSorting on an array is a very common requirement. Especially in the backend. Of course, the front end also has this demand.Of course, array sorting is a ready-made method. That's the way it is sort() .Let's start by looking at this.Standard
If you are the same as me (I am afraid you are), so far, this should be your experience in JSON
Two months ago, youNeverI have heard of JSON
You heard this word a month ago but didn't pay attention to it.
A week ago, you found that this word was
Objective
A very common requirement for sorting an array. Especially at the back end. Of course, the front end also has this demand.
Of course, array ordering is a ready-made method. The sort () method.
Let's take a look at this first.
Standard
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.