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

  • Home
  • SEARCH
  • 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 8595241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:23:18+00:00 2026-06-12T00:23:18+00:00

I have the following code: $.getJSON(‘data.json’, function(data) { var items = []; $.each(data, function(key,

  • 0

I have the following code:

$.getJSON('data.json', function(data) {
  var items = [];

  $.each(data, function(key, val) {
    items.push('<option id="' + key + '">' + val + '</option>');
  });

  $('<select/>', {
    'class': 'my-new-list',
    html: items.join('')
  }).appendTo('body');
});

This works fine for a simple JSON file but I’ve got a bit more complicated data (this is how it’s been given to me):

{
   "Shares": [
   {
      "shareName": "Frontier",
      "shareID": "FML"
   },
   {
      "shareName": "Global Petroleum",
      "shareID": "GBP"
   },
   {
      "shareName": "Tower Petroleum",
      "shareID": "TRP"
   },
   {
      "shareName": "Aquarius Platinum",
      "shareID": "AQP"
   }
   ]
}

This simply populates a drop down menu, how should I modify the syntax so it reads the “ShareName” for each within Shares?

Thanks!

Thanks everyone for the answers, I can only choose one so chose the first reply, but I really appreciate everybody’s input!

  • 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-12T00:23:20+00:00Added an answer on June 12, 2026 at 12:23 am

    Firstly, you’ll have to iterate over data.Shares instead. Note the capital S; JavaScript is case sensitive.

    You’ll also have to reference the shareName and shareID attributes rather than simply the key and value.

      $.each(data.Shares, function(_, val) {
        items.push('<option id="' + val.shareID + '">' + val.shareName + '</option>');
      });
    

    To cement the understanding, what you have is an object (data) which has an attribute (Shares) which is an array of objects. Each object in that array has 2 attributes; shareID and shareName.

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

Sidebar

Related Questions

I have the following code snippet: $.getJSON(http://localhost:8080/images, function(data) { var items = []; $.each(data,
I have the following javascript code: function initSite(){ var site; $.getJSON(www+'init/initSite', function(data) { site
I have the following jquery code: jQuery(function(){ jQuery(select#rooms).change(function(){ var options = ''; jQuery.getJSON(/admin/selection.php,{id: jQuery(this).val(),
I have the following code jQuery.getJSON(encodeURI(strUrl), {address:address,state:state, zip:zip},function(data){ alert('HELLO World!'); }); If for some
I have the following jquery in my code $j.getJSON(http://localhost:8080/WWTestHarnessWEB/ReadersToolkitFinalController.htm?jsoncallback=?, {'uID': 1}, function(data){alert(data);}); The json
Let's say I have the following javascript: (function($) { $.getJSON(url, function(data) { $.each(data.rows, function(index,
I have the following code which retrieves the variable hf using getJSON $.getJSON('../scripts/json.php', function(json)
I have the following snippet of code: $('input#teamName').live('blur', function() { var value = $(this).val();
I am attempting to run the following code snippet: var myVar1 = $.getJSON('myurl', function(json)
I have the following code: $(document).ready(function() { $.getJSON('../includes/_quiz.php?class_id=163&course_id=183',function(data){ $.each(data,function(k,v){ questions[k] = v.question; answers[k*4] =

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.