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?
代言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
}
某草草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