Get an array by “querySelectorAll” on Facebook newsfeed

Hi, I do need your help about HTML…

I am struggling with “querySelectorAll”.

I am studying programming by this book: Learning to Program (written by Steven Foote).

The book says in order to create an “array” of all the images on a Facebook page, go to “Console” on Chrome Dev Tools on Facebook and type this: var images = document.querySelectorAll('div.userContentWrapper img);

But, this code doesn’t show me any array (it just ends up with “undefined”).

it’s probably that Facebook has changed its HTML as this book also says.

Does anyone know how to get an array on Facebook page?

i just can’t get through this part by myself…

Thank you so much.

Your help is very much appreciated!

Actually it still works, just make sure you close add the single quote at the end (before the closing bracket).

Why it is giving you ‘undefined’ because it is a NodeList. Simply type images after it to see the object. You can then cycle through it to get the images using a for-loop or whatever. Or access a specific image using images[3] to get the forth image.

Hope that helps. Happy Coding :slight_smile:

Thank you so much!
I think i have got the array finally;)
as you told me, i just simply typed images and array appeared!
But, why does node give “undefined”?

Because that line of code is simply assigning something (a list of images) to a variable (‘images’). You are not actually outputting anything to the console. To see the list instantly you could type console.log(document.querySelectorAll('div.userContentWrapper img)) although this would just log it to the terminal (i.e. you wouldn’t be able to do anything with the list of images as they haven’t been stored anywhere)