JavaScript · Junior · Question 38 of 75
How do you reliably check that a value is an array?
- ✓Correct answer:
Array.isArray(value) - 2
typeof value === 'array' - 3
value.length !== undefined
Explanation
typeof [] returns 'object', and strings and array-like objects also have length. Array.isArray works even for arrays from other iframes, where instanceof Array fails.