Ten JS one-dimensional arrays, one-dimensional array details

Source: Internet
Author: User

1. One-dimensional arrays

2. Sort, find

3. Multidimensional arrays

array : The basic concept of this data type (reference type / Complex Type / composite type) array for storing a set of data.

Special emphasis : The array in JS can hold various data types (numbers, strings). )

<HTML><Head><Scriptlanguage= "JavaScript">varWeights= [3, 5, 1, 3.4, 2,  -];varAll_weight= 0;varAvg_weight= 0;//Array Traversal for (varI= 0; I<weights.length; I++) {All_weight+=weights[i];} Avg_weight=All_weight/weights.length;//If you want to know the data type//Window.alert (avg_weight.constructor);//avg_weight = new number (avg_weight);//Number under the tofixed () method, converts the number to a string, and the result has a specified digit number after the decimal point. //Keep 2 digits after the decimal point, roundingDocument.writeln ("Overall weight is"+All_weight+"average weight is"+avg_weight.tofixed (2));</Script></Head><Body></Body></HTML>

Results:

Details of the array:

Basic usage

var array name = [ element value, element value ]

the array elements of Javascript can be any type of data .

For example, it can be:var arr =[4, "Hello", true]

The array exists in memory in the form of:

Test code:

<HTML><Head><Scriptlanguage= "JavaScript">varMyval= the;functionABC (val) {Val= -}abc (Myval); Window.alert (Myval); //ResultsvarMyarr=[456, -, the];functionABC2 (arr) {myarr[0]= *;}//iterate through the array before calling for (varI=0; I<myarr.length; I++) {Document.writeln (myarr[i]);} Document.writeln ("<br/>"); //456ABC2 (Myarr);//after the call, iterate over the array for (varI=0; I<myarr.length; I++) {Document.writeln (myarr[i]);} // About</Script></Head><Body></Body></HTML>

Ten JS one-dimensional arrays, one-dimensional array details

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.