Home > Web Front-end > JS Tutorial > 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
Release: 2016-05-16 17:23:56
Original
1186 people have browsed it

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());

}
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template