【问题标题】:how do you access values in an array with topojson如何使用 topojson 访问数组中的值
【发布时间】:2020-02-04 06:00:54
【问题描述】:

我在构建 choropleth 地图时遇到了麻烦,我想弄清楚的一件事是如何从 json 对象访问数组:

这是我在控制台中看到的

var datum=topojson.feature(us, us.objects.states) 

我想专门捕获属性下的名称(例如州名)

【问题讨论】:

  • 为什么不试试 features[i].properties.name
  • 我可以创建这样的函数吗:function(i) { return datum.features[i].properties.name;}

标签: javascript html d3.js


【解决方案1】:
console.log(datum.features[2].properties.name)

假设您想要 features 数组中第二个对象的属性,这应该可以工作。此外,JSON 对象只不过是 javascript 对象,您可以像在 vanilla js 中一样访问属性

【讨论】:

    猜你喜欢
    • 2014-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-15
    • 2021-08-12
    • 2018-09-13
    • 1970-01-01
    相关资源
    最近更新 更多