I am facing an issue with an API call I am using, as it is sending objects with a single property that contains an array value (seen in the keys
property in the response below). However, I need to work with nested arrays in order to utilize the outputted values in another application format like this:
[[value1, value2, value3, value4],[value1, value2, value3, value4]]
. I am considering asking another question specifically addressing the conversion to nested arrays, unless there is an easy fix that someone can suggest (it seems like using .map
might help convert the object).
This is the current format of my objects (as seen in console.log(searchQueries)
):
[ { keys: [ 'hammer' ],
clicks: 1369,
impressions: 3151,
ctr: 0.4344652491272612,
position: 1.004443033957474 },
{ keys: [ 'woodmaking' ],
clicks: 207,
impressions: 6324,
ctr: 0.03273244781783681,
position: 4.35831752055661 },
{ keys: [ 'house trends' ],
clicks: 1,
impressions: 3,
ctr: 0.3333333333333333,
position: 4.666666666666666 },
{ keys: [ 'housing' ],
clicks: 1,
impressions: 36,
ctr: 0.027777777777777776,
position: 6.472222222222222 } ]
byProperty
The above response is generated from the following for-in loop iterating through the API response array originally nested in an object:
for (var prop in res){
searchQueries = res[prop];
console.log(searchQueries);
}
Could the JSON.stringify
method or .toString('keys')
accomplish what I am trying to achieve?