Home > front end >  On a case of a data analysis example is the optimal solution
On a case of a data analysis example is the optimal solution

Time:05-01

I have here array arr is as follows:

{" Area ", "zhejiang", "Name" : "* *"},
{" Area ", "zhejiang", "Name" : "bill"},
{" Area ", "Shanghai", "Name" : "detective"},
{" Area ", "zhejiang", "Name" : "Daisy"},
{" Area ", "Shanghai", "Name" : "notoginseng"},
.
]

Needs to be sorted out into ojb object, the format is as follows:
{
"Zhejiang" : [" zhang ", "li si", "Daisy",... ,
"Shanghai" : [" detective ", "panax notoginseng",... ,
.
}

Because I just contact with Js, don't know if the following writing is the optimal solution, if you, how would you solve this problem?
 let ojb={} 
Arr. ForEach (value=https://bbs.csdn.net/topics/> {
If (value [' Area '] in ojb) {
Ojb [value [' Area ']]. Push (value [' Name '])
} else {
Ojb [value [' Area ']]=[value [' Name ']]
}
})

  • Related