This content originally appeared on CodeSource.io and was authored by Deven
In JavaScript To check if an Object Is an Array we use the static Array.isArray() method.
const fruitNames = ['Apple', 'Mango', 'Banana', 'Grapes', 'pineapple'];
if (Array.isArray(fruitNames)) {
// Our code ends here because it is a valid array
}
isArray() specifically checks for instances of the Array object. If we call it on a different type of collection like Map or Set, it returns false.
The post Javascript Check if an Object Is an Array appeared first on CodeSource.io.
This content originally appeared on CodeSource.io and was authored by Deven
Deven | Sciencx (2021-02-07T12:52:53+00:00) Javascript Check if an Object Is an Array. Retrieved from https://www.scien.cx/2021/02/07/javascript-check-if-an-object-is-an-array/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.