Home  >  Article  >  Web Front-end  >  Array Array definition and sort method usage example in js_javascript skills

Array Array definition and sort method usage example in js_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:23:561164browse

Array array is equivalent to ArrayList in java

definition method:

1: Use new Array(5

) to create array var ary = new Array (5);

2: Use Json syntax, var ary = [1,3,4];

Array sorting:

Example:

Copy code The code is as follows:

function sort(){

var ary=[11,12,3,5,29];

ary.sort(); // Sort by character encoding 11,12,29,3,5;

alert( ary.toString());

ary.sort(function(v1,v2){

return v1-v2;//Custom sorting rules 3,5,11,12,29

});

alert(ary.toString());

}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn