一、创建Object实例

  1、var person = new object();

  2、var person = {};

二、创建数组

  1、(1)var arr = new Array();

    (2)var arr = new Array(20);

    (3)var arr = new Array("name","sex","age");

    (4)var arr =  Array();

  2、(1)var arr = [];

    (2)var arr = ["age","name"];

数组中的方法:

var colors = ["red","blue","green"];

1、Array.isArray(colors);//检测数组

2、var cStr = colors.join("||");    //red||blue||green   以传入join的字符串把数组进行分组

3、var count = colors.push("orange");//在数组末尾添加项,并返回数组长度

4、var item = colors.pop();//移除在数组末尾的项,并返回移除的项

5、var item = colors.shift();//移除在数组头部的项,并返回移除的项

5、var count= colors.unshift("orange");//在数组头部添加项,并返回数组长度

6、colors.reverse();//反转数组顺序

7、color.sort();//对数组进行排序,可以调用一个函数,当返回值为负数和0的时候 ,不对掉,如果为正数则对调。

color.sort(compare);

function compare(value1,value2){

if(value1>value2){

  return 1;

}else if(value1<value2){

  return -1;

}else{

  return 0;

}

}

8、var color1 = color.concat("red","blue");//数组相加,并返回一个新数组

9、var color1 = color.slice(1,3);//截取中的从起始位置到结束位置(不包括结束项)的项,返回一个新数组,但不影响原数组

10、splice(2,1,"red");

11、indexOf(1,"red");//从前向后查  

  lastIndexOf(1,"red");//从后向前查

12、遍历方法

var cFlag = color.every(function(item/*当前项*/,index/*当前项的位置*/,arr/*数组本身*/){});//遍历数组的每一项,如果所有项的处理结果都返回true则为true

var cFlag = color.some(function(item,index,arr){});//遍历数组的每一项,如果某一项的处理结果返回true则为true

var cFlag = color.fliter(function(item,index,arr){});//遍历数组的每一项,如果某项的处理结果返回true则返回该项,构成一个新数组返回

var cFlag = color.map(function(item,index,arr){});//遍历数组的每一项,对每一项的进行处理,返回每一项的处理结果,构成一个新数组返回

color.forEach(function(item,index,arr){});//遍历数组的每一项

13、缩小方法

reduce(function(prev/*前一项*/,cur/*当前项*/,index/*当前项的位置*/,arr/*数组本身*/){//从左向右,遍历数组的所有项,构建成一个最终的值,返回该值

});

reduceRight(function(prev,cur,index,arr){//从右向左,遍历数组的所有项,构建成一个最终的值,返回该值

});

 

posted on 2015-03-20 18:20  鱼之龙  阅读(247)  评论(0编辑  收藏  举报