定义

     1     var  arr=[里边加任何元素]                                              例:var arr=[1,2,3,4,5,]

     2     var arr2=new array                                                         例:var arr2=new Array(1,2,3,4,5)

 

数组取值:

var foo = {a: "alpha", 2: "two"};
console.log(foo.a);    // alpha
console.log(foo[2]);   // two
//console.log(foo.2);  // SyntaxError: missing ) after argument list
//console.log(foo[a]); // ReferenceError: a is not defined
console.log(foo["a"]); // alpha
console.log(foo["2"]); // two

 

 

属性

           arr.length       长度                                                            例alert(arr2.length)

 

 

 

取随机数

Math.ceil(); //向上取整。

Math.floor(); //向下取整。

Math.round(); //四舍五入。

Math.random(); //0.0 ~ 1.0 之间的一个伪随机数。【包含0不包含1】 //比如0.8647578968666494

Math.ceil(Math.random()*10); // 获取从1到10的随机整数 ,取0的概率极小。

Math.round(Math.random()); //可均衡获取0到1的随机整数。

Math.floor(Math.random()*10); //可均衡获取0到9的随机整数。

Math.round(Math.random()*10); //基本均衡获取0到10的随机整数,其中获取最小值0和最大值10的几率少一半。

① parseInt(Math.random()*(m-n)+n) // 生成 [n,m),包含n但不包含m的正整数:

② parseInt(Math.random()*(m-n)+n)+1 // 生成 (n,m],不包含n但包含m的正整数:

③ parseInt(Math.random()*(m-n+1)+n) // 生成 [n,m],包含n和m的随机数:

④ parseInt(Math.random()*(m-n-1)+n+1) // 生成 (n,m),不包含n和m的正整数:

parseInt(10*Math.random()) //输出0~9之间的随机整数

Math.floor(Math.random()*10+1) //输出1~10之间的随机整数

Math.floor(Math.random() * name1.length)  // 从数组长度之间随机取,例如:name1=["唯一","唯二","唯三"],就是取0-2的随机数包括0和2.