Skip to content

Test whether an object is array-like, e.g arguments or NodeList.

Notifications You must be signed in to change notification settings

timoxley/is-collection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Test whether an object is array-like, e.g arguments or NodeList.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published