I have a simple class in Node JS
class Animal {
constructor(name) {
this.name = name;
// more fields ...
}
}
let objects = [];
objects.push(new Animal('Dog'));
objects.push(new Animal('Cat'));
objects.push(new Animal('Dinosaur'));
console.log(objects);
What's the best way to check if this array is instanceof Animal objects , without looping over and checking instanceof of each element ?
check if this array is instanceof Animal objectsDo you meancheck if this array only contains instanceof Animal objects?