1

I´m getting data from php. which I parse to JSON

var d = $.parseJSON(returnData);

d.designer looks like:

[Object, Object, Object] 

0: Object
_id: 1 
family: null
firstname: "XX"
lastname: "YY"
__proto__: Object

1: Object
_id: 2 
family: null
firstname: "XX"
lastname: "YY"
__proto__: Object

2: Object
_id: 5 
family: null
firstname: "XX"
lastname: "YY"
__proto__: Object

With jquery how can I loop trough objects to get:

Id: 1
Id: 2
ID: 5

where ID value is key _id ?

1

1 Answer 1

1

You can use each that return value and key for every element

$.each(d, function( index, value ) {
  console.log("ID: "+index);
});
Sign up to request clarification or add additional context in comments.

1 Comment

that´s it thanks. I changed it a bit to fit: $.each(d.designer, function( index, value ) { console.log("ID: "+index+" = " +value._id); …

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.