0

Trying to learn jquery here so I took a regular javascript snippet that loops through a json collection like this:

 for (var i in msg) {
                        alert(msg[i].Name);
                    }

In this case, the alert box displays the correct name.

However, if I use jquery like this:

  $.each(msg, function(item) {
                        alert(item.Name);
                    });

alert box show undefined for each item in the json collection. What did I miss?

TIA.

1 Answer 1

2

Use the second parameter.

  // this one-------------v
$.each(msg, function(i, item) {
    alert(item.Name);
});
Sign up to request clarification or add additional context in comments.

1 Comment

Could have sworn I tried something like that but still got undefined... anyways, works now, thanks again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.