-2

I thought jquery was returning an array when selecting something. But it does not look like that:

With this html:

<p>A</p>
<p>B</p>
<p>C</p>

And this js:

var p = $('p');
console.log(Array.isArray(p)); // result is false

See JSFiddle Then the selected paragraphs are not in an array. Why is that?

EricC
  • 5,720
  • 13
  • 52
  • 71

1 Answers1

0
var p = $('p');

This code is returning an object, instead of an array. If you want the array result, convert it to array.

var x = p.toArray();
console.log(Array.isArray(x)); // result is true
david
  • 3,225
  • 9
  • 30
  • 43