You can use the Array.isArray() method.This method returns true if the object is an array and false otherwise.
Example:
const myArray = [1, 2, 3];
const myObject = { key: 'value' };
console.log(Array.isArray(myArray)); // Output: true
console.log(Array.isArray(myObject)); // Output: false
The Array.isArray() method is the recommended approach because it accurately identifies arrays, even when dealing with objects from different frames or windows. This is particularly important in web development, where scripts may interact across various contexts.