How to check variable is an array es6

const arr = [1,5,7];

const result = arr.constructor === Array; 

const result = Array.isArray(arr); 

Or

in Lodash: 

const result =  _.isArray(arr);

note: typeof []; // returns 'object'
and arr.length check will fail if variable is a string.

Comments

Popular posts from this blog

world tourism guide Template

Es6 how to check if value is not null or undefined?