JavaScript · Junior · Question 38 of 75

How do you reliably check that a value is an array?

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.

Further reading

Problem with a question

JavaScript · Junior · question 38

Test yourself

Take the JavaScript · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz