Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DoctorDerek/a22a533367bf883b7f1ceb9602397a47 to your computer and use it in GitHub Desktop.
Save DoctorDerek/a22a533367bf883b7f1ceb9602397a47 to your computer and use it in GitHub Desktop.
Using Array.isArray to check for an Array
const myObject = {}
console.log(typeof myObject) // "object"
console.log(Array.isArray(myObject)) // false
const myArray = []
console.log(typeof myArray) // "object"
console.log(Array.isArray(myArray)) // true
const myNull = null
console.log(typeof myNull) // "object"
console.log(Array.isArray(myNull)) // false
const myDate = new Date()
console.log(typeof myDate) // "object"
console.log(Array.isArray(myDate)) // false
const myRegExp = /howdy/
console.log(typeof myRegExp) // "object"
console.log(Array.isArray(myRegExp)) // false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment