Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8395323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:16:18+00:00 2026-06-09T20:16:18+00:00

I want to populate an array of objects with data pulled from a getJSON

  • 0

I want to populate an array of objects with data pulled from a getJSON function.

I’m currently doing it object by object, but know it’d be much cleaner with a for loop…

Here’s the getJSON:

$.getJSON("http://www.reddit.com/r/pics.json?jsonp=?",
    function(data) {

        var imageurl1 = data.data.children[0].data.url;
        var imagecaption1 = data.data.children[0].data.title;;
        var commentlink1 = "http://www.reddit.com" + data.data.children[0].data.permalink;

        var imageurl2 = data.data.children[1].data.url;
        var imagecaption2 = data.data.children[1].data.title;
        var commentlink2 = "http://www.reddit.com" + data.data.children[1].data.permalink;

       }

And here’s the array I’m using the data for

var lightboximages = [
 { 
    src: imageurl1,
    caption: imagecaption1,
    comments: commentlink1
 }, { 
    src: imageurl2,
    caption: imagecaption2,
    comments: commentlink2
 }]

Any help with the loop would be much appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:16:19+00:00Added an answer on June 9, 2026 at 8:16 pm

    Not tested, but this is the idea:

    $.getJSON("http://www.reddit.com/r/pics.json?jsonp=?",
        function(data) {
           var lightboxArray = [];
           for (var i=0; i<data.data.children.length; i++) {
               var child = data.data.children[i];
               var lightboxObj = {"src":child.data.url, "caption":child.data.title, "comments":child.data.permalink};
               lightboxArray.push(lightboxObj);
           }
           // now call some function to process the array we've built
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Actually I want to populate an array to fill up my table view, but
I have a UITableView which I want to populate with details from an array
I want to initialize an array of int and populate it with a range
I want to take an array and use that array's values to populate an
I want to populate my database with test data my user and profile models
So I am making an application that i want to populate a huge array,
When trying to stringify an object that holds an array of objects, I'm getting
If I have a javascript object/assoc. array defined like this: function somefunction(options) { var
I have an array of objects. My object contains a URL( NSString ) and
I'm creating this form with checkboxes that I want to populate from a database.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.