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

108
Views
Looping through JSON data and display them dynamically

I'm looping through JSON data but when I display the data I don't think the quality of the code is good enough, I feel like I'm doing something wrong.

$(function(){
    $.getJSON('data.json', function(data){
        let content = '';

        for(let x in data){
            content += data[x]
        }
        $('.account-image').eq(0).attr('src', data[0].logo)
        $('.account-image').eq(1).attr('src', data[1].logo)
        $('.account-image').eq(2).attr('src', data[2].logo)
        $('.account-image').eq(3).attr('src', data[3].logo)
        $('.account-image').eq(4).attr('src', data[4].logo)
        $('.account-image').eq(5).attr('src', data[5].logo)
        $('.account-image').eq(6).attr('src', data[6].logo)
        $('.account-image').eq(7).attr('src', data[7].logo)
    })
})

Is there a way to loop through the $(.account-image) like the one written above but dynamically?

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

0

How about

$(function() {
  $.getJSON('data.json', function(data) {
    let content = '';

    for (let x in data) {
      content += data[x];
      $('.account-image').eq(x).attr('src', data[x].logo)
    }
  })
})

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!