ES6数组扩展api

Array.of()

let a = Array.of(1,2,3); // [1,2,3]
let b = Array.of(10); // [10]

Array.form()

let a = Array.form(类数组); // 传入类数组,返回真数组

array.find()

let a = [
	{
		id: 1
	},
	{
		id: 2
	},
	{
		id: 3
	}
]
// 找到数组中id为2的那一项
let re = a.find(item => item.id === 2); //{id: 2}

array.findIndex()

let a = [
	{
		id: 1
	},
	{
		id: 2
	},
	{
		id: 3
	}
]
// 找到数组中id为2的那一项的下标
let re = a.findIndex(item => item.id === 2); //1

array.fill()

let a = new Array(10);
// 将数组每一项填充为指定数据
a.fill("www");// ["www","www","www","www","www","www","www","www","www","www"]

array.copyWithin() //我觉得没啥用,想用自己查文档吧

array.includes()

let a = [1,5,7,8,64,5, NaN];
//底层判断使用的是Object.is(), 所以要注意+0与-0的问题
let re = array.includes(60); //false
let w = array.includes(64); //true
let e = array.includes(NaN); //true

你可能感兴趣的:(ES6,javascript,开发语言,ecmascript)