Evaluates obj to determine if it's an array, an array-like collection, or
something else. This is useful when working with the function arguments
collection, NodeLists
and HTMLElement
collections.
Note: This implementation doesn't consider elements that are also
collections, such as <form>
and <select>
, to be array-like.
$ component install timoxley/is-collection
isCollection(document.querySelectorAll('div')) // => truthy (2)
isCollection([]) // => truthy (1)
function() {
return isCollection(arguments)
}() // => truthy (2)
Takes an object and returns a number indicating the results of the test:
- 0: Neither an array nor an array-like collection.
- 1: Real array.
- 2: Array-like collection.
Original code adapted from YUI.