As a newcomer to javascript, I recently received JSON data from the backend in my js file. The JSON data provided looks like this:
{
Vivo:{Time:[20190610,20190611],Price:[2000,2000]},
Huawei:{Time:[20190610,20190611],Price:[3000,3000]},
Maxvalue:3000
}
The JSON data was obtained using the following code:
fetch('/Tmall') //Tmall is the URL from where data is fetched
.then(function(response) {
return response.json();
}).then(function(Data) {
...
}
Now, I need to process the data to display it on the front-end, but I'm unsure of how to separate the data into two distinct variables:
Cellphone =
{
Vivo:{Time:[20190610,20190611],Price:[2000,2000]},
Huawei:{Time:[20190610,20190611],Price:[3000,3000]}
}
Max = {Maxvalue:3000}
I attempted to use a conditional statement to extract the data, but it did not work as expected:
var Cellphone = {}
for (var i = 0; i < Data.length; i++)
{
if (Data.key[i] != 'Maxvalue'){
Cellphone.push(Data[i])
}
}