<script>
// 利用字面量创造数组
var a = [10, 20, 30];
console.log(a);
// new Array创造数组
var p = new Array(20, 30, 45);
console.log(p);
// 检测是否为数组instanceof
var p = [];
var m = {};
console.log(p instanceof Array);
console.log(m instanceof Array);
// Array.isArray检测是否为数组
console.log(Array.isArray(p));
// 数组名.push(添加新的元素);返回长度数组长度
var n = [10, 20, 30];
console.log(n.push(4, 5, 6));
// pop();删除数组最后一个那个数,返回删除那个数
console.log(n.pop());
console.log(n);
// unshift()给前面数组添加新的元素返回数组长度
var f = [12, 3, 45, 78];
console.log(f.unshift(4, 52, 1));
// 删除shift同pop();
console.log(f.shift());
console.log(f);
// 翻转数组reverse();
var i = [27, 38, 19, 44, 54, 68, 113];
console.log(i.reverse());
// 冒泡排序个位数时sort();
i.sort(function (a, b) {
return a - b;
});
console.log(i);
</script>
javaScript两种创造数组方式,instanceof and isArray检查是否为数组,push() and unshift数组追加,pop() and shift()数组删除,简易倒计时
最新推荐文章于 2024-09-11 15:33:18 发布