JavaScript
1.数据类型:boolean number string array function undefined NaN
定义数组:var arr = [2,"2",true];
console.log(arr[2]); (.................................................................//arr[2]索引)
for (var i =0; i < arr.lenght; i++){ (..................................arr.length:数组长度)
console.lod(arr[i]);
} (............................................................................//2 2 true)
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
数组
arr.push() 往数组末尾添加元素
例:var arr = [2,"2",true];
for (var i = 0; i < 3; i++){
arr.push(i);
}
console.log(arr);...........................Array(6)........arr = [2,"2",true,0,1,2]
arr.unshift() 往开头添加元素
例:var arr = [2,"2",true];
for (var i = 0; i < 3; i++){
arr.unshift(i);
}
console.log(arr);...........................Array(6)........arr = [0,1,2,2,"2",true,]
例:var arr = [2,"2",true];
arr.pop();
console.log(arr);...........................Array(2)........arr = [2,"2"]
arr.shift() 删除开头的元素
var arr = [2,"2",true];
arr.shift();
console.log(arr);...........................Array(2)........arr = ["2",true]
arr.join() 功能:把数组中的所有元素放入一个字符串
返回值:字符串
var arr = [2,"2",true];
var array = arr.join(",");
console.log(arr);...........................[2,"2",true] 数组
console.log(array);...........................2,2,true 字符串
console.log(typeof(array));..........................String