I have some JSON data as follows:
{
version: 1,
partitions: {
'0': [ 1616133379 ],
'1': [ 1616133378 ],
'2': [ 1616133380 ]
}
}
I am looping through the data using async.each as follows:
async.each(topicData.partitions, function(data, callback){
console.log('/brokers/topics/' + topic + '/partitions/' + data + '/state');
callback();
},
function(err){
if(err) {
console.log(err);
callback(err);
}
});
The output I'm getting is:
'/brokers/topics/testing/partitions/1616133379/state' '/brokers/topics/testing/partitions/1616133378/state' '/brokers/topics/testing/partitions/1616133380/state'
As you can see the data
item passed through the async.each
function is holding the value of the key/value pair whereas I actually want it to pass the key to produce this output:
'/brokers/topics/testing/partitions/0/state' '/brokers/topics/testing/partitions/1/state' '/brokers/topics/testing/partitions/2/state'
Is there anyway I can get the key passed as opposed to the value?
This has to be run asynchronously.
Thanks