const str="hello world"; const [a,b,...oth]=str; 字元串分割為數組的三種方法: const str="hello world"; const [...str1]=str; const str2=[...str]; const str3=str.spli ...
const str="hello world";
const [a,b,...oth]=str;
字元串分割為數組的三種方法:
const str="hello world"; const [...str1]=str; const str2=[...str]; const str3=str.split("");
提取字元串的屬性和方法:
const str="hello world";
const {length,split}=str;
數值與布爾值的解構賦值:
在對數值或者布爾值結構賦值時,會轉成它的包裝對象
const {valueOf}=1; const {toString}=true; //取別名 const {valueOf:vo}=1; const {toString:ts}=true;
函數參數的解構賦值:
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);