What is the code doing?

Can someone explain what does the following line is doing ?
listArray = Array.prototype.slice.call(listItems)

var listContainer = document.querySelector('.list-container'),
        listItems = document.querySelectorAll('.list-item'),
        listArray = Array.prototype.slice.call(listItems);

querySelectorAll doesn’t return an array, it returns an object that is “array-ish”. We want an array. Array.prototype.slice will copy an array. And .call(listItems) will tell that function to use listItems as the context in which to perform that function.

Basically we are converting something that is not really an array into an array.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.