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

137
Views
Iterating through an object with several json strings in Javascript

Sorry for the rookie question but I couldn't find an answer on similar questions.

I have an object made up of hundreds of json strings and I want to iterate through the object and return specific values from each string.

I have this code

 const leo =
   '{"contractName":"tokens","contractAction":"stake","contractPayload":{"to":"hivebuilder","symbol":"LEO","quantity":"0.161"}}';

 const obj = JSON.parse(leo);

 console.log(obj.contractPayload.to, obj.contractPayload.quantity);

Which returns:

hivebuilder 0.161

That's exactly what I want, but I want to do it to a nested json object like this:

const leo = [
  '{"contractName":"tokens","contractAction":"stake","contractPayload":{"to":"hivebuilder","symbol":"LEO","quantity":"0.161"}}',
  '{"contractName":"tokens","contractAction":"stake","contractPayload":{"to":"pele23","symbol":"LEO","quantity":"1.031"}}',
];

My expected result would be:

hivebuilder 0.161
pele23 1.031

I know I have to use a loop to iterate through each string, but I can't wrap my head around how to do it, any help please?

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

0

try this

let names = leo.map(function (item) {
  const elem = JSON.parse(item);
  return elem.contractPayload.to + " " + elem.contractPayload.quantity;
});

console.log(JSON.stringify(names));

result

["hivebuilder 0.161","pele23 1.031"]
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!