1. 程式人生 > >js實現獲取對象key名

js實現獲取對象key名

aso 獲取 col rop prope span 獲取對象 property per

var arr = {
  "name" : "zh",
  "age" : 22,
}
for(var key in arr){
  //if(arr.hasOwnProperty(key))
  console.log(key);        //鍵名
  console.log(arr[key]);   //鍵值
}

輸出是

"name"

"zh"

"age"

22

js實現獲取對象key名