search

Home  >  Q&A  >  body text

Is a jq object an array or an object??

Many times it is said that the jq object is an array, but when tested with Object.prototype.toString.call(), it is found that it is [Object Object] instead of [Object Array], but the jq object we see on the console looks like It is arranged in the same way as an array, 0, 1... So, is the jq object an object or an array?

给我你的怀抱给我你的怀抱2769 days ago1102

reply all(3)I'll reply

  • 代言

    代言2017-06-12 09:30:41

    It is an object, but it looks like an array. We usually call this structure "array-like"

    The key of this kind of object is the value [0, 1, 2, ...], and it has a length attribute, which is what it looks like below

    selections = {
      0: dom1,
      1: dom2,
      length: 2
    }

    reply
    0
  • 某草草

    某草草2017-06-12 09:30:41

    jQuery object, as the name suggests, is an object. It's just that it does have some features of arrays, such as being able to use subscripts, having a length attribute, etc., but it also has methods that have attributes that arrays don't have. This kind of object can be called an array-like object

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-06-12 09:30:41

    jQuery objects are objects

    reply
    0
  • Cancelreply