JavaScript How do I use jQuery to iterate through nested JSON in a single pass? jquery iterate through array,jquery iterate through elements,jquery iterate

I have a large JSON file with a snippet of the file below. Please ignore the values as they are only used as placeholders for this question.

"restaurants":[
            "name": "Burger King",
            "location": "Seattle, WA",
            "latitude":  0.000,
            "longitude": 0.0000,
            "server": "BKSEATAC1",
            "serverAddress": "127.0.0.1",
            "taskNames": ["BurgerOne","BurgerTwo","BurgerThree"],
            "currentTasks": ["BurgerOne"],
            "tasks": [                       {"name":"BurgerOne","owner":"Tom","startTime":"11:00","endTime":"11:05","duration":"5"},

Using jQuery, I am able to iterate through the "restaurants" and set values for variables in the following manner:

$.getJSON('json/DATA.json', function(data) {
  $.each(data.restaurants, function(key, val) {
    var restaurantName = this.name;
    var restaurantLocation = this.location;

(Please note that the code above is just a snippet)

To iterate through the "inner" JSON starting at "tasks", I use the following code

$.getJSON('json/DATA.json', function(data) {
  $.each(data.restaurants, function(key, val) {
    $.each(val.tasks, function(i, j){
    var taskName = this.name;
    var taskOwner = this.owner;

(Another snippet)

The problem I am having is that if I combine the code, variables are assigned correctly in the first iteration but not the second. The loop iterates through "restaurants" and then executes the rest of the code in the script and only then iterates through the "tasks". I need all the variables set on the first pass. Any tips or suggestions would be appreciated.

Thanks in advance!

Answer:1

I have three sliding panels in my html. The thing is that panels overlay each other when open. I would like to get a function that create an event when one panel (eg. #panel1) is open already and the ...

I have three sliding panels in my html. The thing is that panels overlay each other when open. I would like to get a function that create an event when one panel (eg. #panel1) is open already and the ...

  1. jquery sliding panels
  2. jquery sliding panel demo
  3. jquery sliding panel left to right
  4. jquery sliding panel from right
  5. jquery sliding panel from left
  6. jquery ui sliding panel
  7. jquery vertical sliding panel
  8. jquery mobile sliding panel
  9. jquery sliding sidebar panel
  10. jquery create sliding panel
  11. jquery sliding overlay panel
  12. jquery sliding menu panel
  13. jquery lateral sliding panel
  14. jquery side sliding panel plugins
  15. jquery side sliding panel

I have a Meteor method that I call from the client, which in turn updates all fields in a single document. In the last line of code below I try to immediately run the same update on the client to get ...

I have a Meteor method that I call from the client, which in turn updates all fields in a single document. In the last line of code below I try to immediately run the same update on the client to get ...

  1. meteor shower side effects

I'm trying to create a select list control that supports data with a tree structure and has typeahead capability. The data looks like this: Category -> SubCategory Category2 -> ...

I'm trying to create a select list control that supports data with a tree structure and has typeahead capability. The data looks like this: Category -> SubCategory Category2 -> ...

  1. typeahead select list
  2. typeahead select dropdown
  3. typeahead select only from list

I'm using the Twitter oembed api, and now have the following code on my page: <div class='row'> <iframe id="twitter-widget-0" scrolling="no" frameborder="0" allowtransparency="true" ...

I'm using the Twitter oembed api, and now have the following code on my page: <div class='row'> <iframe id="twitter-widget-0" scrolling="no" frameborder="0" allowtransparency="true" ...

  1. center twitter embed
  2. center twitter embed wordpress
  3. centre twitter embed