# 数组中插入数组

### 问题描述

`
“points”: [{

``````    "accuracy": 37.52,
"direction": 0,
"height": 175.47,
"locatetime": 1593320683164,
"location": "120.374254,36.088865",
"speed": 0
},
{
"accuracy": 36.448,
"direction": 0,
"height": 175.46,
"locatetime": 1593320685163,
"location": "120.374254,36.088865",
"speed": 0
},
{
"accuracy": 32.16,
"direction": 0,
"height": 175.43,
"locatetime": 1593320687164,
"location": "120.374254,36.088865",
"speed": 0
}]
`
``````

###想要的数据类型
`
[

``````[120.23, 26.45],
[120.23, 26.45],
[120.23, 26.45],
[120.23, 26.45],``````

]
`

## 回答

`points.map(v => v.location.split(',').map(k=>Number(k)))`

``````//输出
[
[120.374254, 36.088865]
[120.374254, 36.088865]
[120.374254, 36.088865]
]``````

``points.map(point => point.location.split(",").map(n => Number(n)))``
``points.map(item => item.location).map(item => item.split(',').map(t => Number(t)))``
``````const result = points.map(item => {
// 如果需要精确到小数点后两位，使用tofixed，并再数字化即可，具体可看demo
return item.location.split(',').map(every => Number(every))
})``````

demo 链接

``````let point = []
points.map(item=>{
let arr = []
arr.push(item.location)
point.push(arr)
})``````