Categories
JavaScript Answers

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

Spread the love

To detect if argument is array instead of object with Node.js, we call the util.isArray method.

For instance, we write

const util = require("util");

const isArray = util.isArray([]);
const isArray2 = util.isArray(Array(55));

to call isArray with the value we want to check if it’s an array.

isArray should return true for both since both arguments are arrays.

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 *