The point of confusion is - when we check the type of array or object using typeof
get the return value as Object. So what's the main difference between them.
Asked
Active
Viewed 738 times
-1

Mohan Rajput
- 634
- 9
- 21

Suyash Madhav
- 49
- 1
- 2
- 9
-
Arrays are objects – charlietfl Oct 27 '18 at 11:50
-
https://stackoverflow.com/questions/4775722/check-if-object-is-an-array – ksav Oct 27 '18 at 11:51
1 Answers
0
You can check using constructor.name
const myArr = []
const myObj = {}
console.log(`myArr is an ${myArr.constructor.name}`)
console.log(`my Obj is an ${myObj.constructor.name}`)

ksav
- 20,015
- 6
- 46
- 66