const str="hello world";
const [a,b,...oth]=str;
String array is divided into three methods:
const str="hello world"; const [...str1]=str; const str2=[...str]; const str3=str.split("");
Properties and methods of extraction string:
const str="hello world";
const {length,split}=str;
Boolean value and deconstruction of assignment:
When numerical or Boolean in assignment, it will turn into object to be wrapped
const {valueOf}=1; const {toString}=true; //取别名 const {valueOf:vo}=1; const {toString:ts}=true;
Deconstruction assignment function parameters:
function swap([a,b]){ return [b,a]; } let arr=[1,2]; arr=swap(arr);
function getInfo({ name, age, friend1="cyy1", friend2="cyy2" }){ console.log(name); console.log(age); console.log(friend1); console.log(friend2); } //无序传入参数 var obj={ age:18, name:"cyy" } getInfo(obj);