Problem with typeof

function isArray(val) {
return typeof val === ‘array’;
}

I have warning ‘invalid type comparison’ how to fix it? I try replace ‘array’ with Array but not sure about this solution.

there is no “array” type in javascript - arrays have type “object”

use Array.isArray to check for arrays

const a=[2,4,6]
const b={0:2, 1:4, 2:6, length:3}
typeof a // "object"
Array.isArray(a) // true
typeof b // "object"
Array.isArray(b) // false
1 Like