【发布时间】:2018-03-14 09:09:04
【问题描述】:
这是我的 json 对象:
{
"id": 2,
"service": "mobile",
"min": "20",
"per": "10",
"tax": "1",
"categoryservices": [
{
"category": {
"id": 1,
"name": "laptop"
}
},
{
"category": {
"id": 2,
"name": "software"
}
}
]
}
我想要这样的输出:
{
"id": 2,
"service": "mobile",
"min": "20",
"per": "10",
"tax": "1",
"cats": [1,2] // this 1 and 2 is coming from categoriesservices array inside the category object i have id
}
如何使用地图功能做到这一点?我是javascript新手,哪个是好的方法图或forloop?
【问题讨论】:
-
这个问题重复这里是答案stackoverflow.com/questions/19590865/…
-
我添加了答案,希望它会按照您的期望工作。
-
你能试试答案吗,对你有用吗
标签: javascript arrays json object