Suppose, I have a simple following code snippet of Javascript.
let data = {
"ethusd": {
"at": 1581416882,
"ticker": {
"buy": "218.87",
"sell": "219.0",
"low": "0.0",
"high": "0.0",
"open": 209.09,
"last": "0.0",
"volume": "72877.8789",
"avg_price": "213.699103431748658920247612509",
"price_change_percent": "-100.00%",
"vol": "72877.8789"
}
},
"trstusd": {
"at": 1581416882,
"ticker": {
"buy": "0.0",
"sell": "0.0",
"low": "0.0",
"high": "0.0",
"open": "0.0",
"last": "0.0",
"volume": "0.0",
"avg_price": "0.0",
"price_change_percent": "+0.00%",
"vol": "0.0"
}
},
"trsteth": {
"at": 1581416882,
"ticker": {
"buy": "0.0",
"sell": "0.0",
"low": "0.0",
"high": "0.0",
"open": "0.0",
"last": "0.0",
"volume": "0.0",
"avg_price": "0.0",
"price_change_percent": "+0.00%",
"vol": "0.0"
}
}
}
for (let element in data)
{
let innerElement = data[element];
for (let innerData in innerElement)
{
if (innerData !== "at")
{
let internalData = innerElement[innerData];
for (let x in internalData)
{
console.log(x,internalData[x]);
}
}
}
}
What I tried on that above code is to get the value of buy and sell in particular. So I wrote a code in that way. Is this a good way to extract data from a javascript object or JSON data format? If not, what are the efficient ways and good practices?