const arr = ['1', '2', '3'];
const str = 'Devsheet';
is_array = Array.isArray(arr);
console.log(is_array);
is_array = Array.isArray(str);
console.log(is_array);
Arrays in javascript contain one or multiple items inside them and you can get array items using its index.
In the code snippet, we have two variable arr and str that need to be checked whether they are array or not. When we execute Array.isArray(arr) it will return true and Array.isArray(str) will return false.
Live Demo
Array.isArray();
Array.isArray(null);
Array.isArray(true);
Array.isArray(undefined);
Array.isArray({});
Array.isArray(500);
Array.isArray([]);
Array.isArray([NaN]);
Array.isArray([9])
Array.isArray(new Array());
Array.isArray(new Array('x', 'y', 'z'));
Array.isArray(new Array(3));
0 Comments