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.