1. includes
string.includes(searchvalue, start)
searchvalue : 必需,要查找的字符串。
start:可选,设置从那个位置开始查找,默认为 0。
var str = "Hello world, welcome to the Runoob。";
str.includes("world");//输出:true
var str = ['cc','bb','dd'];
str.includes("c");//输出 false
str.includes("cc");//输出 true
2. some
一真即真,只要一个符合条件即可
var ages = [3, 10, 18, 20];
function checkAdult(age) {
return age >= 18;
}
ages.some(checkAdult);//输出true
3. every
一假即假,要全部符合条件
var ages = [32, 33, 16, 40];
function checkAdult(age) {
return age >= 18;
}
ages.every(checkAdult);//输出false
4. 复制对象
var ages = [32, 33, 16, 40];
var c={...ages};//ex 1
var d=Object.assign({}, ages)//ex 2
5. Object.assign()
如果原对象(object1)中与新对象(object2)中存在相同的属性,那么原对象的属性会被覆盖
const object1 = {a: 1, b: 2,c: 3};
const object2 = Object.assign({c: 4, d: 5}, object1);
//输出:a: 1 b: 2 c: 3 d: 5
6. concat
连接多个数组
const object1 = [1,2,3];
const object2 =[4,5,6];
console.log( object1.concat(object2));//输出:[1, 2, 3, 4, 5, 6]