I assure you this is not a duplicated question. Despite my attempts with JSON.parse(), it seems to be ineffective.
Here's the issue at hand: I recently received assistance from an answer that was both crucial and enlightening. However, the code provided in that response has generated a result that I am struggling to extract individual values from as it appears as a seamless string of continuous values:
the following code snippet:
var result = {};
for ( var i = 0; i < arr.length; i++ ) {
var key = "asset: " + arr[ i ].geo + ' ym: ' + arr[ i ].ym + ' venue: ' + arr[ i ].venue + ' value';
result[ key ] = (result[ key ] || 0 ) + arr[ i ].value ;
}
Logger.log(result);
transforms this given array:
arr = [
{value:1.0, venue: "binance", ym:20181.0, geo:"eur"},
{value:6.0, venue: "binance", ym:20181.0, geo:"eur"},
{value:2.0, venue: "bitstamp", ym:20181.0, geo:"eur"},
{value:5.0, venue: "binance", ym:20182.0, geo:"eur"},
{value:1.0, venue: "binance", ym:20183.0, geo:"eur"},
{value:3.0, venue: "binance", ym:20181.0, geo:"usd"},
{value:3.0, venue: "binance", ym:20182.0, geo:"usd"},
{value:3.0, venue: "binance", ym:20183.0, geo:"usd"},
{value:2.0, venue: "binance", ym:20181.0, geo:"pop"},
{value:2.0, venue: "binance", ym:20182.0, geo:"pop"},
{value:2.0, venue: "binance", ym:20183.0, geo:"pop"},
{value:2.0, venue: "binance", ym:20181.0, geo:"dot"},
{value:2.0, venue: "binance", ym:20182.0, geo:"dot"}
];
and transforms it into an unbroken sequence of data:
{asset: eur ym: 20181 venue: bitstamp value=2.0, asset: eur ym: 20182 venue: binance value=5.0, asset: dot ym: 20183 venue: binance value=2.0, asset: eur ym: 20183 venue: binance value=1.0, asset: usd ym: 20181 venue: binance value=3.0, asset: sol ym: 20183 venue: binance value=1.0, asset: pop ym: 20183 venue: binance value=2.0, asset: dot ym: 20182 venue: binance value=2.0, asset: dot ym: 20181 venue: binance value=2.0, asset:...
<span>(truncated for brevity)</span>
...cad ym: 20183 venue: binance value=3.0, asset: sol ym: 20182 venue: binance value=1.0, asset: pop ym: 20182 venue: binance value=2.0, asset: pop ym: 20181 venue: binance value=2.0, asset: cad ym: 20181 venue: binance value=3.0, asset: cad ym: 20182 venue: binance value=3.0, asset: eur ym: 20181 venue: binance value=7.0}
I find myself unable to utilize this data effectively since extracting specific values - like in a standard array with result[i].value
or result[i].ym
- proves to be a challenging task due to its continuous format where isolating a particular part feels daunting. Despite verifying with Logger.log(typeof result);
which returns object
, I still encounter difficulties in extracting any meaningful information from it.
While I deeply appreciate the assistance provided through this code, the fault lies solely with me. It stems from my lack of experience, preventing me from deciphering this result effectively at the moment.