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]
]