http://lib.csdn.net/article/reactnative/40118
与传统的全局方法isFinite()和isNaN()的区别在于,传统方法先调用Number()将非数值的值转为数值,再进行判断,而这两个新方法只对数值有效,非数值一律返回false
ES6将全局方法parseInt()和parseFloat(),移植到Number对象上面,行为完全保持不变
Array.from
方法用于将两类对象转为真正的数组:类似数组的对象(array-like object)和可遍历(iterable)的对象(包括ES6新增的数据结构Set和Map)Array.of
方法用于将一组值,转换为数组,主要目的,是弥补数组构造函数Array()的不足Array.of(3, 11, 8) // [3,11,8]
Array.of(3) // [3]
Array.of(3).length // 1
Array() // []
Array(3) // [, , ,]
Array(3, 11, 8) // [3, 11, 8]
Array.prototype.copyWithin(target, start = 0, end = this.length)
[1, 2, 3, 4, 5].copyWithin(0, 3)
// [4, 5, 3, 4, 5]
// 将3号位复制到0号位
[1, 2, 3, 4, 5].copyWithin(0, 3, 4)
// [4, 2, 3, 4, 5]
// -2相当于3号位,-1相当于4号位
[1, 2, 3, 4, 5].copyWithin(0, -2, -1)
// [4, 2, 3, 4, 5]
//find方法,用于找出第一个符合条件的数组成员,没有则返回undefined
Array.prototype.find(function(value, index, arr) {//当前值,当前位置,原数组
return value > 9;
})
//findIndex方法,返回第一个符合条件的数组成员的位置,没有则返回-1
Array.prototype.findIndex(function(value, index, arr) {//当前值,当前位置,原数组
return value > 9;
})
[‘a‘, ‘b‘, ‘c‘].fill(7)
// [7, 7, 7]
[‘a‘, ‘b‘, ‘c‘].fill(7, 1, 2)//填充值,开始位置,结束位置
// [‘a‘, 7, ‘c‘]
for (let index of [‘a‘, ‘b‘].keys()) {//遍历键名
console.log(index);
}
// 0
// 1
for (let elem of [‘a‘, ‘b‘].values()) {//遍历键值
console.log(elem);
}
// ‘a‘
// ‘b‘
for (let [index, elem] of [‘a‘, ‘b‘].entries()) {//遍历键值对
console.log(index, elem);
}
// 0 "a"
// 1 "b"
0 in [undefined, undefined, undefined] // true 0位置有值
0 in [, , ,] // false 0位置没值
concat()
连接两个或更多的数组,并返回结果join()
把数组的所有元素放入一个字符串。元素通过指定的分隔符进行分隔pop()
删除并返回数组的最后一个元素push()
向数组的末尾添加一个或更多元素,并返回新的长度reverse()
颠倒数组中元素的顺序shift()
删除并返回数组的第一个元素slice(start,end)
从某个已有的数组返回选定的元素 sort(sortby)
对数组的元素进行排序,sortby可选,但必须是函数splice(index,howmany,item1,.....,itemX)
删除元素,并向数组添加新元素 unshift()
向数组的开头添加一个或更多元素,并返回新的长度http://lib.csdn.net/article/reactnative/40118
原文:https://www.cnblogs.com/qianjin888/p/9142522.html