javascript / angular 如何把object转成array

取出的api 格式是纯object格式

{"name":"james","city":"Taipei","country":"Taiwan"}

用ngFor跑表格跑不出来 因为不支援object格式

要怎么把他变成array格式?

想变成

[
    {"name":"james","city":"Taipei","country":"Taiwan"}
]

方法

let o = {"name":"james","city":"Taipei","country":"Taiwan"}
let arr = [o]

返回Array

let addressPoints = response;
for (const key in addressPoints) {
        if (addressPoints.hasOwnProperty(key)) {
          const a = addressPoints[key];
        }
}

https://segmentfault.com/q/1010000017148640

posted @ 2019-06-04 16:34  TTonlyV5  阅读(657)  评论(0编辑  收藏  举报