0

i have multiple objects as response from an api call with Ajax, how do i "print" the data that's inside the object?

$.ajax({
    url: 'url',
    dataType: 'json',
    type: 'post',
    contentType: 'application/json',
    data: JSON.stringify( { parameters } ),
    processData: false,
    success: function( data ){
      console.log(data); <- this log all objects, i want the info inside the objects
    },
});

enter image description here

how do i print every single "variable" for each object, or storage on an array.

1
  • If you just click on the arrows in the console view, the objects will open up ? Commented Sep 29, 2016 at 18:45

2 Answers 2

2

If you want only to see the data,

console.log(JSON.stringify(data,null,4));

If you want to use the data, you have to iterate over the array and access each object separately, or use come collection methods ( see libraries such as underscore or lodash (https://lodash.com/) )

Sign up to request clarification or add additional context in comments.

2 Comments

Ok, that worked fine only to see the data, but iterate the objects i use .each() and im fine atm, some advice for start using lodash or why use it over .each()?
My personal view is that libraries such as lodash (or underscore) provide a multiple functionality which is not part of vanilla javascript. So, for consistency reasons I'd use the library when applicable. Also, because there might be minor details in the usage, which do have effect on the outcome. For instance, some iterative methods don't check for hasOwnProperty, which may lead to a nasty side effects when working with complex objects/frameworks.
0

Like this?

for(int i = 0; i < data.length; i++) {
  console.log(data[i]);  
 }

Comments

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.