Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
How to Loop through JSON Objects having Objects and Arrays Inside

let mything = {
  "holders": [{
    "address": "0xbe0eb53f46cd790cd13851d5eff43d12404d33e8",
    "balance": 8.623839536582375e24,
    "share": 52.02
  }, {
    "address": "0xf977814e90da44bfa03b6295a0616a897441acec",
    "balance": 4.5e24,
    "share": 27.14
  }]
};

let m = Object.entries(mything);
console.log(m);

The above is a json data, stored in a file, now what I want to do is to loop over this whole file which has 2000 of such entries, get just the address part of each entry and append it in a url, so how would I do the looping part?? Any code Snippet for javaScript would be lovely. Cudos.

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You can use the map function to get a one liner :

const data = {"holders": [{
  "address": "0xbe0eb53f46cd790cd13851d5eff43d12404d33e8",
  "balance": 8.623839536582375e24,
  "share": 52.02
},{
  "address": "0xf977814e90da44bfa03b6295a0616a897441acec",
  "balance": 4.5e24,
  "share": 27.14
}]};

const url = "https://my.url/";
const urls = data.holders.map(holder => `${url}${holder.address}`);

console.log(urls);

about 4 years ago · Juan Pablo Isaza Report

0

Since holders object is an array, you can loop over it like below, and make use of the address like constructing the URL as per your logic inside the loop. Here's the example of storing the addresses in an array:

var original = {
  "holders": [{
    "address": "0xbe0eb53f46cd790cd13851d5eff43d12404d33e8",
    "balance": 8.623839536582375e24,
    "share": 52.02
  }, {
    "address": "0xf977814e90da44bfa03b6295a0616a897441acec",
    "balance": 4.5e24,
    "share": 27.14
  }]
};

var addresses = [];
for (let holder of original.holders) {
  addresses.push(holder.address);
}
console.log(addresses)

about 4 years ago · Juan Pablo Isaza Report

0

const data = {"holders": [{
  "address": "0xbe0eb53f46cd790cd13851d5eff43d12404d33e8",
  "balance": 8.623839536582375e24,
  "share": 52.02
},{
  "address": "0xf977814e90da44bfa03b6295a0616a897441acec",
  "balance": 4.5e24,
  "share": 27.14
}]};

for(const obj of Object.values(data)) {
    for(const arr of obj) {
        // Your code
    }
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!