JavaScript陣列&物件


Posted by oack7426 on 2020-06-26

陣列(Array)

陣列寫法

var Array [];

ex:
var Array [1,2,3......,10];

{Array}.length 取得陣列長度
{Array}.push({內容}) 把新的資訊push到array
{Array[{索引值}]} 取得陣列裡面的特定資訊

var A = 1;
var B = 2;
.
.
.
var Z = 26;

陣列寫法 (含有物件寫法)
var engNum = [{ A : 1},{ B : 2}......,{ Z : 26}]

取值

var engNum = [{A:1},{B:2}];
console.log(engNum[0]);

結果
{A:1}

儲存性質相似的資訊
螢幕快照 2020-06-25 下午1.39.07

物件(Object)

物件寫法

var Object = {key:value};

ex:
var Object = {A:1,B:2,C:3};

取值

var peter = {
    name: 'peter',
    scores: [1, 2, 3],
    address: 'taipei city',
    phone: '010101',
    father: {
        name: 'nick',
        phone: '12345'
    }
};

var key = 'name';
console.log(peter.name);
console.log(peter[key]);
console.log(peter.father.name);
console.log(peter['father']['name']);

結果
peter
peter
nick
nick

#javascript







Related Posts

[MTR04] W2 D10 Array 內建函式及 console.log / return 的差異

[MTR04] W2 D10 Array 內建函式及 console.log / return 的差異

打造後台管理系統的好幫手:Ant Design

打造後台管理系統的好幫手:Ant Design

[ 筆記 ] React 04 - 如何寫 CSS

[ 筆記 ] React 04 - 如何寫 CSS


Comments