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);

轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/140006.html
標籤:JavaScript
上一篇:ES6 物件的解構賦值
