function demo(a,...b){
console.log(a,b);//b为数组 2,3,4,5
}
demo(1,2,3,4,5);
let [a,...b] = [1,2,3,4,5];
console.log(a,b);
function demo({username,password}){
console.log(username,password);
}
demo({username:'root',password:'123456'});
const arr = [1,2,3];
console.log(...arr);
const arr1 = [1,2,3];
const arr2 = [4,5,6];
const arr3 = [...arr1,...arr2];
console.log(arr3);
1
2
3
function demo(a,b){
return a+b;
}
const arr1 = [1,2];
const arr2 = [4,5];
console.log(demo(...arr1));
console.log(demo(...arr2));
let str = "1234";
const arr = Array.from(str);
console.log(arr);
在下面这种方法里面,对象里面的key和数组的下标对应,不能是其他值,length表示数组的长度
const Arr = {
2:"a",
3:"b",
length:4,
}
console.log(Array.from(Arr));
const arr = [1,2,3,4];
let num = arr.find(item=>item==3);
console.log(num);
找数组包对象
const arr = [
{realname:"张三1",age:18},
{realname:"张三2",age:17},
{realname:"张三3",age:19},
{realname:"张三4",age:17},
];
console.log(arr.find(item=>item.age==17));
const arr = [1,2,3,4];
console.log(arr.findIndex(item=>item==4));
const arrobj = [
{realname:"张三1",age:18},
{realname:"张三2",age:19},
{realname:"张三3",age:15},
{realname:"张三4",age:14},
]
console.log(arrobj.findIndex(item=>item.age==19));
const arr = [1,2,3,4];
console.log(arr.includes(10));//有就返回true 没有就返回false
function demo(){
return "end";
}
let es6 = "es6!";
let str = `hello,${es6},${demo()}`;
console.log(str);
let str = "hello,es6!";
console.log(str.startsWith("hello"));//判断某个字符串前面是否包含hello 有就为true
console.log(str.endsWith("es6!"));//与startsWith相反
console.log("hello".repeat(4));
- 张三,50
成绩及格的第一个同学为
有疑问可评论