Skip to content
Test whether an object is array-like, e.g arguments or NodeList.
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
test
.gitignore
Makefile
Readme.md
component.json
index.js

Readme.md

is-collection

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.

Installation

$ component install timoxley/is-collection

Usage

isCollection(document.querySelectorAll('div')) // => truthy (2)
isCollection([]) // => truthy (1)

function() {
  return isCollection(arguments)
}() // => truthy (2)

API

isCollection(object)

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.

Credit

Original code adapted from YUI.

License

BSD

Something went wrong with that request. Please try again.