on 2021 Nov 22 2:09 PM
Request clarification before answering.
Hi Burak,
I gave it a go and came up with this rather ugly solution. It works for a maximum of two nested result-arrays inside the top-level result array. I guess you know the kind of response you will get so you will you can decide if two is enough or if you need more levels. You could more levels in a similar fashion as I did or spent some time on it and come up with some kind of recursive function.
if (a.result) var b = a.result
for (i = 0; i < b.length; i++) {
Object.keys(b[i]).forEach(key => {
if (b[i][key].result) b[i][key] = b[i][key].result
Object.keys(b[i][key]).forEach(key2 => {
if (b[i][key][key2] && b[i][key][key2].result) b[i][key] = b[i][key][key2].result
})
})
}
console.log(b)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yess!!
I also found a similar solution. Thank you very much!
_edit: function(oData) {
var aData = oData.results;
var aKeys = [];
for (var i = 0; i < aData.length; i++) {
aKeys = [];
aKeys = Object.keys(aData[i]);
for (var j = 0; j < aKeys.length; j++) {
if (aData[i][aKeys[j]] instanceof Object && aData[i][aKeys[j]].hasOwnProperty("results")) {
aData[i][aKeys[j]] = aData[i][aKeys[j]]["results"];
}
}
}
return aData;
},
User | Count |
---|---|
62 | |
8 | |
7 | |
7 | |
5 | |
5 | |
5 | |
4 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.