Home > front end >  Analytic: let jsonArr=[{" one ": [{" 2 _5" : 10000}], "two" : [{"
Analytic: let jsonArr=[{" one ": [{" 2 _5" : 10000}], "two" : [{"

Time:02-07

Analytic: let jsonArr=[{" one ": [{" 2 _5" : 10000}], "two" : [{" 1 ": 10000}, {" 2" : 10000}, {" 3 ": 10000}]}], structure changed, see below how to change?

Let keys=[];
Let keychilds=[];
Let values=[];

For (the let I=0; I & lt; JsonArr. Length; I++) {
JsonArr. ForEach (function (m) {
N in m for (var) {
Keys. Push (n);
M [n]. ForEach (function (h) {
For (var) in h k {
Keychilds. Push (k);
[k] values. Push (h);
}
});
}
});
}

Let data={
https://bbs.csdn.net/topics/Keys: keys,
Keychilds: keychilds,
Values: values,
}

The console. The log (' data ', data);

CodePudding user response:

The period for code to the following
JsonArr. ForEach (e=& gt; {
Keys. Push (... Object. The keys (e));
Object. Values (e). The forEach (se=& gt; {
Keychilds. Push (... Object. The keys (se));
Values. Push (... Object. Values (se));
});
});

CodePudding user response:

What's the problem with this?
What do you need?
  • Related