let names=['Jhon','David','Mark'];
console.log(Array.isArray(names));
// true
let user={id:1,name:'David'};
console.log(Array.isArray(user));
// false
let age 18;
console.log(Array.isArray(age));
// false
Array.isArray([]) //true
Array.isArray({}) //false
Array.isArray('') //false
Array.isArray(null) //false
Array.isArray([1, 2, 3]); // true
Array.isArray({toto: 123}); // false
Array.isArray("tototruc"); // false
Array.isArray(undefined); // false
Array.isArray([1, 2, 3]); // true
Array.isArray('asdf'); // false
if(Array.isArray(colors)){
//colors is an array
}
if(Array.isArray(myVarToTest)) {
// myVatToTest is an array
} else {
// myVarToTest is not an array
}
let variable1 = [2, 3]
let variable2 = "test";
variable1.constructor === Array; // true
variable2.constructor === Array; // false
// Check if something is an Array
// just like you do with "typeof"
Array.isArray([1, 2, 3]); // true
Array.isArray('asdf'); // false
function isArray(value) {
return Object.prototype.toString.call(value) === "[object Array]";
}
const arr = ["name"]
console.log(Array.isArray(arr)); // true
// I know javascript can be hard but see this example and you will learn
// Javascript if condition and array example
var people = ["filex", "alex", "jon"];
var peopleNeeded = people[1]; // 1 is the index bc the index starts from 0
if (peopleNeeded <= people[1]) {
console.log("alex needed");
} else {
console.log("lol");
}
if(Object.prototype.toString.call(someVar) === '[object Array]') {
alert('Array!');
}