数组-2

    join(separator)
    var arr = ["旋之华", 18, "男"];
    var str = arr.join("|");
    console.log(str);
    console.log(typeof str); // string
    console.log(arr);
    将数组的元素组成一个字符串,以separator为分隔符,默认为,
1     // push()和pop()  数组的最后操作
2     var arr = ["张三", "李四", "王五"];
3     var count = arr.push("赵六", "宋小宝");
4     console.log(count);
5     console.log(arr);
6 
7     var item = arr.pop();
8     console.log(item);
9     console.log(arr);
1  var arr = ["张三", "李四", "王五"];
2  console.log(arr.reverse());
3  console.log(arr);
1  concat()
2  var arr = [1, 3, 5, 7, 9];
3  var copyArr =  arr.concat(11, "王小二", ["张三", "李四"]);
1  // shift() 和 unshift()  shift()是删除第一项,返回被删除元素的值,如果数组为空返回Undefined   unshift返回数组的长度
2  var arr = ["张三", "李四", "王五"];
3  console.log(arr.shift());
4  console.log(arr.shift());
5  var count = arr.unshift("小沈阳", "宋小宝");
1 // indexOf()和 lastIndexOf()
2  var arr = [2, 4, 6, 8, 8, 6, 4, 2];
3  console.log(arr.indexOf(4, 2));//-1
4  console.log(arr.indexOf(4));  //1
5  console.log(arr.lastIndexOf(4));  //6 从后往前找
6  console.log(arr.indexOf("4")); // -1
7  console.log(arr.lastIndexOf("4")); // -1    

 

posted @ 2019-07-12 02:12  疏影横斜水清浅  阅读(165)  评论(0编辑  收藏  举报