Blogger Information
Blog 7
fans 0
comment 0
visits 4683
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
独孤九贱 JavaScript 笔记(六) —— 数组方法
残羽的博客
Original
646 people have browsed it

定义方式

方式一:

var arr = new Array();

arr[0] = data1;

arr[1] = data2;

方式二:

var arrr = [data1,data2,data3,...];


基本的操作数组函数

var lang = ['html','css','javascript'];

/* 数组长度 */
lang.length
//输出结果:3

/* 向数组尾部添加元素 */
lang.push('jquery','bootstrap')
//输出结果:["html","javascript","jquery","bootstrap"]

/* 向数组头部添加元素 */
lang.unshift('前端','开心')
//输出结果:[“前端”,“开心”,"html","javascript","jquery","bootstrap"]

/* 从尾部删除数组元素并输出删除的元素 一次只能删除一个 */
lang.pop()
//输出结果:"bootstrap"

/* 从头部删除数组元素并输出删除的元素 一次只能删除一个 */
lang.shift()
//输出结果:"前端"

/* 清空数组中指定下标的内容 */
delete lang[1]
//输出结果:true
//此时的 lang 数组内容为:["开发", undefined*1,"css","javascript","jquery"]

/* 删除 或 添加 指定下标的数组元素,返回被删除的元素 */
//函数解释:起始位置,包括起始位置向后删除的数量,新添加的数据内容(可选)
lang.splice[1,1,'开心']
//输出结果:undefined*1
//此时, lang 数组内容为:["开发", "开心","css","javascript","jquery"]


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments