如何获取对象密钥

时间:2018-11-15 20:18:14

标签: javascript

有人可以帮我一些代码来获取对象内的密钥,以便我拥有

var data =[ {
  "customer_name": "Marietjie",
  "customer_surname": "Short",
  "times": "12:00 to 13:00",
  "order_id": "241918",
  "vendor": [
    "Pick n Pay",
    "Woolworths"
  ],
  "customer_phone": "0609880707",
  "smart_shopper": "",
  "dischem_reward": "",
  "woolworths_reward": ""
}]
var name = data.customer_name;
console.log(name);

我想获得客户名的价值,我尝试了var name = data.customer_name,但是我得到了undefined可以帮助我使用代码

1 个答案:

答案 0 :(得分:0)

您的对象在数组中。

您不能只忽略数组。

var object = data[0];
var name = object.customer_name