instanceof array code example
Example 1: if object is array javascript
Array.isArray(object);
Example 2: in javascript check is is an array or not
Array.isArray(yourItem)
Example 3: js check if array
Array.isArray([1, 2, 3]);
Array.isArray('asdf');
Example 4: js class check if new instance
new Date() instanceof Date;
Example 5: insanceof
The instanceof operator tests to see if the prototype property of a constructor
appears anywhere in the prototype chain of an object. The return value is a
boolean value.
For example :-
function Car(make, model, year) {
this.make = make;
this.model = model;
this.year = year;
}
const auto = new Car('Honda', 'Accord', 1998);
console.log(auto instanceof Car);
console.log(auto instanceof Object);
Example 6: javascript check if array is in array
var array = [1, 3],
prizes = [[1, 3], [1, 4]],
includes = prizes.some(a => array.every((v, i) => v === a[i]));
console.log(includes);