Categories
JavaScript Answers

How to detect if argument is array instead of object with Node.js?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *