Sometimes, we want to detect if argument is array instead of object with Node.js.
In this article, we’ll look at how to detect if argument is array instead of object with Node.js.
How to detect if argument is array instead of object with Node.js?
To detect if argument is array instead of object with Node.js, we use the util.isArray method.
For instance, we write
const util = require("util");
const isArray = util.isArray([]);
to call util.isArray with an empty array to check if the argument is an array.
true is returned if it is.
Conclusion
To detect if argument is array instead of object with Node.js, we use the util.isArray method.