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]);	// true
Array.isArray('asdf');		// false

Example 4: js class check if new instance

new Date() instanceof Date;  // => true

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);
// expected output: true

console.log(auto instanceof Object);
// expected output: true

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);