Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print array in console [closed]

Tags:

javascript

I have a newbie question. How do i print this info in the console? the object shown in the console I have an object that is not a DOM element and it has an array inside. I print the object but I need to get the elements of the array.

How do I print the children of "bannerdata"?

I wrote: console.log(varName.bannerdata);

That is as far as i get.

like image 392
Daijard Avatar asked Dec 18 '22 15:12

Daijard


1 Answers

Just click the little "Arrow" next to your object item, item in array will expand and you will get the properties for object stored in the array.

Or use JSON.stringify(yourArrayHere) as @trincot suggested, example:

var bannerData = [{item:1},{item:2},{item:3}];
console.log(JSON.stringify(bannerData));

JSON.stringify() method will convert a JavaScript value/object to a JSON string.

If you are interested in learning more about Chrome Developer tools including use of API console.log() and other tricks, you can start by reading the following:

https://developers.google.com/web/tools/chrome-devtools/

http://tutorialzine.com/2015/03/15-must-know-chrome-devtools-tips-tricks/

like image 68
GibboK Avatar answered Feb 01 '23 11:02

GibboK