Я пытаюсь перебрать json-данные в реагировать на натив. Я хочу создать новый массив с другими key
, и values
будет зацикленным результатом json. Я пробовал следующее, но ничего не работает, так какожидается. Формат ответа json будет следующим.
json
0: {key: 0, id: 0, type: "section", title: "A1. India's Economic Development", duration: 0, …}
1: {key: 1, id: "1", type: "unit", title: "1. India as a Developing Economy", duration: 0, …}
2: {key: 2, id: "2", type: "unit", title: "2. Understanding India’s economic transition", duration: 0, …}
3: {key: 17, id: 0, type: "section", title: "A2. National Income", duration: 0, …}
4: {key: 18, id: "5", type: "unit", title: "1. India in the global economy", duration: 0, …}
5: {key: 19, id: "6", type: "unit", title: "2. China, India and the rise of Asia", duration: 0, …}
Я хочу такой массив
const dataArray = [
{
title: "India's Economic Development",
content:
"India as a Developing Economy",
"Understanding India’s economic transition"
},
{
title: "National Income",
content:
"India in the global economy",
"China, India and the rise of Asia"
}
]
Следующийэто цикл, который я сделал, но ничего не идет. Пожалуйста, помогите
.then((response) => response.json())
.then((responseData) => {
responseData.map(detail => {
let resultk = [];
//console.log( detail.data.curriculum);
for (var i = 0, j = 0; i < detail.data.curriculum.length; i++) {
curr = detail.data.curriculum;
console.log(curr.title);
if (curr.type === "section") {
resultk['title'] = curr.title;
this.result[j++] = resultk;
} else if (curr.type === "unit") {
resultk['content'] = curr.title;
}
}
console.log(resultk)
})
})