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 8083457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:29:01+00:00 2026-06-05T17:29:01+00:00

I have a JSON feed that is pulling into an each statement. What I

  • 0

I have a JSON feed that is pulling into an each statement. What I would like to do is the for loop var i I would like this value to be used in the each statement. In the example below the for loop will run 0, 1, 2. If i == 1 then I would like to run the JSON feed but only for the i = 1 value. Currently when the if statement gets triggered the JSON each statement runs through all the items b/c it’s i value starts at 0. So the console.log I have in place returns 0, 1, 2. I would like it to return only 1. Thank you for any help.

EDIT
My focus is to make $.each(data.DATA, function(i, item) { the i within this each statement to use the number that i is equal to in the for loop statement. So if there are 3 items in the JSON file, only item 1 will be ran.

for (var i = 0; i < 2; i++) {
    if (i == 1) {
        $.getJSON("/json/v2_ilt_map.cfm?feedtype=ILTMAP_SCHEDULED&customerID=1&TrainingObjectParent=3", {}, function(data, i) {
            $.each(data.DATA, function(i, item) {
                console.log(i);
            }
        }):
    }
}​
  • 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-05T17:29:03+00:00Added an answer on June 5, 2026 at 5:29 pm

    You’ll need to introduce an additional function scope to make this work.

    function checkOnly(i) {
      return function(data) {
        $.each(data.DATA, function(ii, item) {
          if (ii == i) console.log(ii);
        });
      };
    }
    
    for (var i = 0; i < 2; i++) {
        if (i == 1) {
            $.getJSON("/json/v2_ilt_map.cfm?feedtype=ILTMAP_SCHEDULED&customerID=1&TrainingObjectParent=3", {}, checkOnly(i));
        }
    }
    

    Here, the callback passed to $.getJSON is created inside another function. By doing that, the variable “i” that’s examined in the .each() loop is a copy of the “i” from the for loop. The handler function therefore has a fixed value to compare against.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have JSON text that looks like this: { ok: true, totalPages: 256, arReports:
I have a JSON feed that drupal spits out time in this format: 2010-12-16T04:41:35Z
I have the following JSON content that I'm pulling from a service feed: [
I have created a jQuery plugin that grabs a JSON feed (in this case
I have a json feed from this URL which contains 20 fields and I
I have JSON string that has nested objects with dynamic names that vary each
i have json data like this {GetStudentDetails: {TotalCount:5, RootResults:[ {city:West Chester,country:USA,state:PA ,student_id:100}, {city:Philly,country:USA,state:PA,student_id:101}, {city:Buffalo,country:USA,state:NY,student_id:102},
I have the following json content that I'm pulling from a different location: JSON
So I have an app that downloads and parses a JSON feed with some
NodeJS + Express, MongoDB + Mongoose I have a JSON feed where each record

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.