从javascript数组中提取Lat / Long数据

时间:2016-05-24 07:29:50

标签: javascript arrays

我想从下面提到的数组中提取Lat / Long值。请帮帮我。

var products = {"PolygonCords":"[[51.65040675460229,0.034332275390625],[51.613752957501,0.028839111328125],[51.61034179610213,0.1812744140625],[51.642737480428536,0.157928466796875]]"};

1 个答案:

答案 0 :(得分:1)

使用 JSON.parse() 解析json字符串,并使用forEach迭代数组

var products = {
  "PolygonCords": "[[51.65040675460229,0.034332275390625],[51.613752957501,0.028839111328125],[51.61034179610213,0.1812744140625],[51.642737480428536,0.157928466796875]]"
};

JSON.parse(products.PolygonCords).forEach(function(v) {
  console.log(v[0], v[1])
})