0

When I was looking someone's code, and I saw the following code:

var items = [].slice.call(
  document.querySelectorAll(".item")
);

I really don't know what does the slice do here so I'm quite curious about this.

It seems not different between the code below:

var items = document.querySelectorAll(".item")
Kurt
  • 678
  • 1
  • 7
  • 24
  • 2
    It converts the return value of `querySelectorAll()` into an array. The modern way to do this is `var items = Array.from(document.querySelectorAll('.item'))` – slebetman Oct 12 '22 at 03:59

0 Answers0