Код: Выделить всё
[
{
"thumbsup": [
{
"feedback": "thumbsup",
"feedbackMessage": "It was easy to make a payment",
"feedbackAllFlows": [
"map"
]
},
{
"feedback": "thumbsup",
"feedbackMessage": "Fast and simple.",
"feedbackAllFlows": [
"map"
]
},
{
"feedback": "thumbsup",
"feedbackMessage": "Very fast",
"feedbackAllFlows": [
"sales",
"cases"
]
},
{
"feedback": "thumbsup",
"feedbackMessage": "Very easy to use.",
"feedbackAllFlows": [
"off shore"
]
},
{
"feedback": "thumbsup",
"feedbackMessage": "Great help. Once I asked tge correct question",
"feedbackAllFlows": [
"off shore",
"disconnect",
"thanks"
]
},
{
"feedback": "thumbsup",
"feedbackMessage": "Very quick",
"feedbackAllFlows": [
"pay later"
]
},
{
"feedback": "thumbsup",
"feedbackMessage": "improve the billing and help better understanding the bill cycle",
"feedbackAllFlows": [
"pay later",
"high"
]
},
{
"feedback": "thumbsup",
"feedbackMessage": "Everything was simple and easy. Quick responses made the process a lot faster.",
"feedbackAllFlows": [
"activate"
]
},
{
"feedback": "thumbsup",
"feedbackMessage": "Very helpful",
"feedbackAllFlows": [
"pay later"
]
}
]
}
]
< /code>
Я хочу разбить это на свои собственные массивы для комментариев из массива обратной связи ... < /p>
Я бы хотел, чтобы выход был похож на это ... < /p>
[
{
"thumbsup": [
{
"map": [
"It was easy to make a payment",
"Fast and simple."
]
},
{
"sale": [
"Very fast"
]
},
{
"cases": [
"Very fast"
]
},
{
"off shore": [
"Very easy to use.",
"Great help. Once I asked tge correct question"
]
},
{
"disconnect": [
"Great help. Once I asked tge correct question"
]
},
{
"thanks": [
"Great help. Once I asked tge correct question"
]
},
{
"pay later": [
"Very quick",
"improve the billing and help better understanding the bill cycle",
"Very helpful"
]
},
{
"high": [
"improve the billing and help better understanding the bill cycle"
]
},
{
"equipment_activate_device": [
"Everything was simple and easy. Quick responses made the process a lot faster."
]
}
]
}
]
< /code>
Я попробовал следующее, но он не объединяет имена потоков должным образом ... < /p>
var mainArr = [];
tup[0].thumbsup.map(obj => {
//console.log(obj.feedbackAllFlows)
obj.feedbackAllFlows.map ((flow) => {
mainArr.push({flow: obj.feedbackMessage})
})
})
console.log(mainArr)
< /code>
Я ожидал, что «поток» будет именем потока, но это не правильно, он использует поток в качестве значения ключа, а не фактический поток. < /p>
Вот мой полный код: < /p>
ar mainArr = [];
tup[0].thumbsup.map(obj => {
//console.log(obj.feedbackAllFlows)
obj.feedbackAllFlows.map ((flow) => {
mainArr.push({flow: obj.feedbackMessage})
})
})
console.log(mainArr)< /code>
let tup = [
{
"thumbsup": [
{
"feedback": "thumbsup",
"feedbackMessage": "It was easy to make a payment",
"feedbackAllFlows": [
"map"
]
},
{
"feedback": "thumbsup",
"feedbackMessage": "Fast and simple.",
"feedbackAllFlows": [
"map"
]
},
{
"feedback": "thumbsup",
"feedbackMessage": "Very fast",
"feedbackAllFlows": [
"sales",
"cases"
]
},
{
"feedback": "thumbsup",
"feedbackMessage": "Very easy to use.",
"feedbackAllFlows": [
"off shore"
]
},
{
"feedback": "thumbsup",
"feedbackMessage": "Great help. Once I asked tge correct question",
"feedbackAllFlows": [
"offshore",
"disconnect",
"thanks"
]
},
{
"feedback": "thumbsup",
"feedbackMessage": "Very quick",
"feedbackAllFlows": [
"pay later"
]
},
{
"feedback": "thumbsup",
"feedbackMessage": "improve the billing and help better understanding the bill cycle",
"feedbackAllFlows": [
"pay later",
"high"
]
},
{
"feedback": "thumbsup",
"feedbackMessage": "Everything was simple and easy. Quick responses made the process a lot faster.",
"feedbackAllFlows": [
"activate"
]
},
{
"feedback": "thumbsup",
"feedbackMessage": "Very helpful",
"feedbackAllFlows": [
"pay later"
]
}
]
}
];
Подробнее здесь: https://stackoverflow.com/questions/794 ... ys-content