IE 最新版瀏覽器 IE11 還不支援 Destructuring。
JavaScript ES6 Array and Object Destructuring Assignment 陣列和物件的解構賦值
解構賦值 (Destructuring Assignment)是一個在 ES6 的新特性,目的用於提取陣列或物件中的資料變成獨立變數。
物件解構賦值的基本使用方法如下:
let obj = {
website: "pjchender",
country: "Taiwan"
}
let {website, country} = obj;
console.log(website); // pjchender
console.log(country); // Taiwan
Learn More →
圖片來源: PJChender 部落格
所以真正被建立和賦值的 let{ } 當中,冒號(:)後的變數。
let obj = {
website: "pjchender",
country: "Taiwan"
}
let {website:wb, country:ct} = obj;
console.log(website, country); // Error:website in not defined
console.log(wb, ct) // "pjchender", "Taiwan"
物件解構賦值的用途相當多(可參考阮一峰-ECMAScript 6 入門),其中在提取 JSON 數據時相當方便:
let data_JSON = {
id: 74,
website: "pjchender",
country: "Taiwan",
detail:{
add: "Tainan",
phone: "0933333333"
}
}
let {id, website, country, detail} = data_JSON;
console.log(id, website, country, detail);
正規表達式撰寫方法有兩種
Nov 6, 2023$ git remote -v $ git remote set-url origin https://hostname/USERNAME/REPOSITORY.git add remote $ git remote add origin https://github.com/USER/REPO.git http的網址 https://[hostname]/USERNAME/REPOSITORY.git SSH的網址
Feb 14, 2023{%hackmd theme-dark %} 安裝 nvm 環境,Node.js 開發者必學(Windows、Mac 均適用) mac上的nvm 附上網址做參考 https://www.jianshu.com/p/622ad36ee020 這個有移除作法 https://yimincai.net/2020/install-and-uninstall-nvm-on-macos/
Sep 27, 2022{%hackmd theme-dark %} tags: react 高階組件(High Order Component)官方文檔 高階組件的命名,官網的做法是使用小寫開頭。 胡子大哈說高階組件就是一個函數,傳給它一個組件,它返回一個新的組件。
Sep 21, 2022or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up