0

I wrote a utility function for my nextjs project. In there, I got something that I unexpected. I initialised an empty array which be filled with the data later. When I type check that empty array, it shows an object. I don't want an object. I want an array. Why? Could someone told me why does it happen.

strong textProblem screenshoot

MooreJohn90
  • 164
  • 1
  • 2
  • 11
  • 4
    In JS, arrays are objects. `Arrays are list-like objects whose prototype has methods to perform traversal and mutation operations.` -MDN – DecPK Aug 25 '21 at 02:05

1 Answers1

1

Yes typeof array is an object in javascript

if you want to check one variable is an object or array then you can use Array.isArray()

console.log(Array.isArray(arr)) // true
console.log(Array.isArray(obj)) // false