JavaScript:Array属性方法
var arr=[,,,,];
console.dir(arr);
var pro=Object.getPrototypeOf(arr);
console.dir(pro);

来一个个的查看数组的属性,方法
1.Array的静态方法
var arr=[,,,,];
console.log(Array.isArray(arr)) //true
2.arr的属性
var arr=[,,,,];
var con=arr.constructor;
console.dir(con);
var length=arr.length;
console.dir(length);

3.arr的方法
1.concat
var arr=[,,,,];
var a2=arr.concat("hongda");
console.log(a2);
var a3=arr.concat(["hong","da","da"]);
console.log(a3);
var a4=arr.concat("hongda1","hongda2",["hongda3","hongda4"]);
console.log(a4);

2.every,some,map,forEach
var arr=["hong","da","da2","da3"];
//every
var result=arr.every(function(value,index,array){
console.log("value:"+value+" index:"+index+" array:"+array);
return true;
});
console.log(result);
//some
var result=arr.some(function(value,index,array){
console.log("value:"+value+" index:"+index+" array:"+array);
return true;
});
console.log(result);
//map
var result=arr.map(function(value,index,array){
console.log("value:"+value+" index:"+index+" array:"+array);
return value+index;
});
console.log(result);
//forEach
var result=arr.every(function(value,index,array){
console.log("value:"+value+" index:"+index+" array:"+array);
});
console.log(result);

1,filter,按指定函数过滤元素,汇集返回值为true元素组成新的数组,函数值类型为布尔
2,forEach,在每一个元素上执行函数,函数返回类型为空
3,every,贪婪的试图匹配每一个元素,真到有一个返回false为止,函数值类型为布尔
4,some,懒惰的企图找到一个元素合乎要求,只要有一个返回true停止,函数值类型为布尔
5,map,使用同一函数处理每一个元素并返回,汇集返回结果组成新数组,函数返回类型为元素类型
3.filter
var arr = [, "element", , "the", true];
var result = arr.filter(
function (value) {
return (typeof value === 'string');
}
);
console.log(result); //element,the
5.lastIndexOf
var ar = ["ab", "cd", "ef", "ab", "cd"];
console.log(ar.lastIndexOf("cd")); //4
6.reduce
var arr=["hong","da","da2","da3"];
var result=arr.reduce(function(previousValue,currentValue,currentIndex,array){
console.log("previousValue:"+previousValue+" currentValue:"+currentValue+" currentIndex:"+currentIndex+" array:"+array);
});

var arr=["hong","da","da2","da3"];
var result=arr.reduce(function(previousValue,currentValue,currentIndex,array){
console.log("previousValue:"+previousValue+" currentValue:"+currentValue+" currentIndex:"+currentIndex+" array:"+array);
return currentValue+currentIndex;
});
console.log(result);

var arr=["hong","da","da2","da3"];
var result=arr.reduce(function(previousValue,currentValue,currentIndex,array){
console.log("previousValue:"+previousValue+" currentValue:"+currentValue+" currentIndex:"+currentIndex+" array:"+array);
return previousValue+currentValue;
});
console.log(result);

7.reduceRight
var arr=["hong","da","da2","da3"];
var result=arr.reduceRight(function(previousValue,currentValue,currentIndex,array){
console.log("previousValue:"+previousValue+" currentValue:"+currentValue+" currentIndex:"+currentIndex+" array:"+array);
return previousValue+currentValue;
});

8.reverse
var arr=["hong","da","da2","da3"];
var result=arr.reverse();
console.log(result);
console.log(arr);

9.sort
var a = new Array(, , , , , ); var b = a.sort();
document.write(b);
document.write("<br/>"); // This is ASCII character order.
// Output: 1,10,11,2,3,4) // Sort the array elements with a function that compares array elements.
b = a.sort(CompareForSort);
document.write(b);
document.write("<br/>");
// Output: 1,2,3,4,10,11. // Sorts array elements in ascending order numerically.
function CompareForSort(first, second)
{
if (first == second)
return ;
if (first < second)
return -;
else
return ;
}
http://msdn.microsoft.com/zh-tw/library/k4h76zbx(v=vs.94).aspx
JavaScript:Array属性方法的更多相关文章
- JavaScript Array 数组方法汇总
JavaScript Array 数组方法汇总 1. arr.push() 从后面添加元素,返回值为添加完后的数组的长度 var arr = [1,2,3,4,5] console.log(arr.p ...
- JavaScript Array filter() 方法
JavaScript Array filter() 方法 var ages = [32, 33, 16, 40]; function checkAdult(age) { return age > ...
- JavaScript -Array.form方法
Array.from方法可以把一个类数组或者课遍历对象转换为一个正真的数组 语法 Array.from(arrayLike[, mapFn[, thisArg]]) 参数 arrayLike 想要转换 ...
- JavaScript Array数组方法详解
Array类型是ECMAScript中最常用的引用类型.ECMAScript中的数据与其它大多数语言中的数组有着相当大的区别.虽然ECMAScript中的数据与其它语言中的数组一样都是数据的有序列表, ...
- javascript Array类型 方法大全
1,创建数组 //第一种是使用Array构造函数 var colors = new Array(); var colors = new Array(20); //创建length为20的数组 var ...
- JavaScript Array 对象方法 以及 如何区分javascript中的toString()、toLocaleString()、valueOf()方法
1.concat() 2.join() 3.pop() 4.push() 5.reverse() 6.shift() 7.unshift() 8.slice() 9.sort() 10.splice( ...
- JavaScript Array reverse 方法:颠倒数组中元素的顺序
在JavaScript中,Array对象的reverse()方法将颠倒(反转)数组中元素的顺序.arr.reverse()在原数组上实现这一功能,即,reverse()会改变原数组. 例1:将数组元素 ...
- JavaScript Array map() 方法
语法: array.map(function(currentValue,index,arr), thisValue) currentValue:必须.当前元素的值index:可选.当期元素的索引值ar ...
- JavaScript.Array.some() 方法用法
定义和用法:some() 方法用于检测数组中的元素是否满足指定条件(函数提供). some() 方法会依次执行数组的每个元素: 如果有一个元素满足条件,则表达式返回true , 剩余的元素不会再执行检 ...
随机推荐
- sparkuser is not in the sudoers file. This incident will be reported.
切换到root身份$su -(注意有- ,这和su是不同的,在用命令"su"的时候只是切换到root,但没有把root的环境变量传过去,还是当前用户的环境变量,用"su ...
- 冒泡排序快速版(C)
冒泡排序C语言版:在每轮排序中检查时候有元素位置交换,如果无交换,说明数组元素已经有序,无需继续排序 #include <stdio.h> #include <stdlib.h> ...
- tcp3次握手,https加密,ca认证
参考: https://baijiahao.baidu.com/s?id=1570143475599137&wfr=spider&for=pc
- sql优化 表连接join方式
sql优化核心 是数据库中 解析器+优化器的工作,我觉得主要有以下几个大方面:1>扫表的方法(索引非索引.主键非主键.书签查.索引下推)2>关联表的方法(三种),关键是内存如何利用 ...
- mysql 内置功能 存储过程 创建无参存储过程
操作哪个数据库,就把存储过程建到那个数据库 例如 现在use db2; 应该把存储过程 建立到db2数据库里 创建无参存储过程 delimiter // # 设置mysql结束符合为// create ...
- npm设置淘宝镜像
npm config set registry https://registry.npm.taobao.org --global npm config set disturl https://npm. ...
- ab压力测试遭遇apr_socket_recv: Connection reset by peer (104) 怎么办
ab -r -c 2000 -n 200000 www.baidu.com 其实只要加上-r就可以了.但是为什么呢?ab --help就知道了 当Socket接收到错误的时候不退出,就是这句.事实 ...
- python3与mysql:创建表、插入数据54
import pymysql db = pymysql.connect(host=',db='jodb1',port=3307,charset='utf8') # #测试连接开发库成功 # db = ...
- 记两个国外CTF的弱pwn
两道题都来自CSAW CTF 18.PWN学得不够多,如果哪里错了,欢迎留言交流. 第一个题 get_it checksec检查之后,发现栈保护没开,很可能是栈溢出.IDA打开F5看伪源码. int ...
- VS2013密钥(所有版本)
Visual Studio Ultimate 2013 KEY(密钥):BWG7X-J98B3-W34RT-33B3R-JVYW9 Visual Studio Premium 2013 KEY(密钥) ...