在D3中访问对象内部的数组元素

时间:2017-02-05 15:53:05

标签: javascript json object d3.js

如何访问此对象内的数组元素。例如,如果我希望数组中的字符串对抗Ellen Doe,我如何将其存储在变量中?我使用D3从外部JSON文件调用它。

{
  "Marley, Bob": [
    "string 1", 
    "string 2"
  ], 
  "Doe, Ellen": [
    "String 3", 
    "String 2", 

  ]
}

1 个答案:

答案 0 :(得分:-1)

您可以通过Bracket notation访问对象属性

get = object[property_name];
object[property_name] = set;



var obj = {
  "Marley, Bob": [
    "string 1", 
    "string 2"
  ], 
  "Doe, Ellen": [
    "String 3", 
    "String 2", 

  ]
}
    console.log(obj["Doe, Ellen"]);