Home  >  Article  >  Web Front-end  >  Basic knowledge of JS arrays (summary)

Basic knowledge of JS arrays (summary)

青灯夜游
青灯夜游forward
2019-11-26 15:04:231815browse

This article summarizes some basic knowledge of JS arrays for everyone. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

Basic knowledge of JS arrays (summary)

Array: Store a set of ordered data

The role of array: Store multiple items at once Data

How to define an array:

1. Constructor defines array: var array name=new Array();

2. Literal Define an array in a quantitative way: var array name=[];

[Related course recommendations: JavaScript video tutorial]

The meaning of the following arrays:

var 数组名=new Array(); //  空数组
var 数组名=new Array(值); //  数组定义了,有长度
var 数组名=new Array(值1,值2,值3....); //  定义数组并且有多个数据
var 数组名=[]; //  空数组
var 数组名=[值1,值2,值3]; //  有三个数据

Array elements: is the data stored in the array

Array length: is the number of elements in the array

Array index (subscript): Start from 0 and end with the length of the array minus 1

Set the element value of the array through the subscript: Array name [index] =value

Access the element value of the array through subscript:Array name[index]

The meaning of the following array:

var arr1=new Array();//空数组
var arr2=new Array(5);//长度为5的数组,每个数据的值是undefined
var arr3=new Array(1,2,3,4,5);//长度为5分数组,
var arr4=[];//空数组
var arr5=[1,2,3];//长度为3的数组
var arr6=["red","blue","green",1,true];//数组中元素的值的类型可以不一样

var arr7=[];
//设置数组的元素的值
arr7[0]=10;
arr7[1]=20;

This article comes from the js tutorial column, welcome to learn!

The above is the detailed content of Basic knowledge of JS arrays (summary). For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete