Created
November 17, 2020 19:45
-
-
Save DoctorDerek/a22a533367bf883b7f1ceb9602397a47 to your computer and use it in GitHub Desktop.
Using Array.isArray to check for an Array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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