HLJ 发布于
2019-04-23 16:59:46

Javascript将JSON字符串对象转换为数组值

Javascript将JSON字符串对象转换为数组值
<script type="text/javascript">
const obj = {
    "locations": [{
        "info": "7811 N. Octavia",
        "longitude": -87.8086439,
        "latitude": 42.0229656
    }, {
        "info": "PO Box 271743",
        "longitude": -73.087749,
        "latitude": 41.6032207
    }, {
        "info": "P.O. Box 269",
        "longitude": -86.7818523,
        "latitude": 34.0667074
    }]
};
locations = obj.locations.map(({info, longitude, latitude}) => [info, longitude, latitude]);
console.log(locations);
</script>
输出结果:
[
  ["7811 N. Octavia",-87.8086439,42.0229656],
  ["PO Box 271743",-73.087749,41.6032207],
  ["P.O. Box 269",-86.7818523,34.0667074]
]
当前文章内容为原创转载请注明出处:http://www.good1230.com/detail/2019-04-23/412.html
最后生成于 2022-08-30 09:07:52