//[]陣列 const colors = ["yellow", "red", "blue"]; const any = [123, true, "Tom"];//可混合 console.log(`colors陣列共用${colors.length}筆`); let myColor = colors[2]; //讀取陣列,陣列從從0開始算 console.log(myColor); // "blue" myColor = colors[3]; //陣列從0開始 console.log(myColor); // undefined
let colors = []; //寫入 colors[0] = "blue"; colors[1] = "yellow"; colors[3] = "red"; console.log(colors);//["blue","yellow", null,"red"] console.log(`colors陣列共用${colors.length}筆`); //還是會有四筆 //push加入最後一筆 colors.push("black"); console.log(colors);//["blue","yellow",null,"red","black"];2.物件
//物件{} const family = { myFather: "David",//屬性 : 值 myMonther: "Mary",//屬性 : 值 dogs: 3 }; console.log(family.myFather); //讀取物件中屬性
let home = {}; home.myMonther="May";//寫入 home.myFahter ="Kevin"; home.cats = 4; console.log(home); //{"myMonther": "May","myFahter": "Kevin", "cats": 4}參考資料
六角線上課