JavaScript(JS) JS check if an object is an array

www‮itfigi.‬dea.com

In JavaScript, you can check whether an object is an array or not using the Array.isArray() method. Here's an example:

const myObj = [1, 2, 3];

if (Array.isArray(myObj)) {
  console.log('myObj is an array');
} else {
  console.log('myObj is not an array');
}

In the above example, Array.isArray() method is used to check whether myObj is an array or not. If myObj is an array, it will return true and the code inside the if block will execute. If myObj is not an array, it will return false and the code inside the else block will execute.