Let:
const:
let arr = [3,4,5,6];
let age = arr[0];
let sex = arr[1];
let num = arr[2];
let abc = arr[3];
let qwe = arr[4];
let [sex,age,num,abc,qwe] = arr;
console.log(age)
console.log(sex)
console.log(num)
console.log(abc)
console.log(qwe) //undefined
var str = "hello world";
var [a,b,c,d,e,f,g] = str;
console.log(a)
console.log(b)
console.log(c)
console.log(d)
console.log(e)
var obj = {
name:"admin",
sex:1,
age:18
}
var name = obj.name
var {
sex,age,name} = obj;
console.log(name)
console.log(age)
console.log(sex)
function fn([a,b,c,d,e]){
}
var arr = [2,3,4,5,6]
fn(arr)
function fn(){
return {
year:2020,month:12,date:31
}
}
var {
tear,month,date} = fn()
快速交换两个变量的值
var a = 10;
var b = 20;
var [a,b] = [b,a]
console.log(a)
console.log(b)
var str = "hello";
console.log(str.repeat(5));
console.log(str.includes("a"));
console.log(str.startsWith("e"));
console.log(str.endsWith("o"));
str.codePointAt()
String.formCodePoint()
var s1 = "这是字符" + "这是拼接的字符";
var s2 = `这
也
是
字
符
${
s1 }`;
console.log(s1);
console.log(s2);
()=>{}
)特点:
使用场景:
var f = ()=>{
console.log(1);
}
f();
var fn = a=>{
console.log(a)
}
fn("hello")
var fn = a=>"hello " + a;
console.log(typeof fn);
...
)类似与解构赋值,展开复杂数据(数组和对象)
var arr = [34,56,87,25,69];
console.log(Math.max(...arr));
var arr = [34,56,87,25,69];
ES6中取数组的最大或最小值
console.log(Math.max(...arr));
var obj = {
name:"admin"
}
var people = {
age:18,
sex:1,
...obj
}
console.log(people)
var obj = {
name:"admin"
}
var obj2 = {
...obj}
obj2.name = "root";
console.log(obj)
console.log(obj2)
console.log(...obj)
console.log(name:"admin")
var s1 = Symbol();
var s2 = Symbol();
console.log(s1);
console.log(s2);
console.log(typeof s2);
console.log(s1 === s1);
console.log(s1 === s2);
set:
重复的参数,不会添加,类型为对象,没有索引号和字符长度
使用for - of
遍历;s.siez
查看长度(可用于数组去重)
var s = new Set([4,5,2,1]);
s.add("hello")
s.add(4)
s.add("4")
console.log(s);
console.log(typeof s);
console.log(s[0])
console.log(s.length)
for(var i of s){
console.log(i);
}
console.log(s.size)
Array.from(set([3,3,2,4,5])) //一行代码实现数组去重
map:
set(“键”,值),对象添加属性的方法
键=>值
连接size
查看字符长度for-of
遍历
var m = new Map();
m.set("name","admin");
m.set("age",18);
m.set("sex",1);
m.set("show",function(){
});
console.log(m)
console.log(typeof m)
console.log(m.size)
console.log(m[0])
console.log(m.length)
console.log(m.get("name"))
console.log(m.get("sex"))
console.log(m.get("age"))
for(var i of m){
console.log(i)
}