Alko Alko - 1 year ago 181
jQuery Question

jQuery, JSON array push

Im having a little problem making this work:

Here is my json array pulled via ajax:

"message": [{
"title": "Account",
"id": 1
}, {
"title": "Content",
"id": 2
}, {
"title": "Other",
"id": 3

here is javascript:

var items = [];
$.get("settings.php", {
getlink: 1,
}, function(json) {
$.each(json.message, function() {



But for some reason items array is always empty []
I can see in firebug, json returned array, but I'm not able to push it.

Answer Source

Use the index, value that $.each return :

$.each(json.message, function(index, value) {

NOTE : $.each() is different than .each().

Hope this helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download