0

If so, how can I detect the difference between them.

I've noticed that you can't do typeof Array hence I'm looking for different solution to see the difference.

Niels
  • 529
  • 2
  • 6
  • 20
  • 1
    There's no such thing as "class" in Javascript (except for syntactic sugar). – deceze Dec 05 '16 at 13:26
  • [Check if object is array?](http://stackoverflow.com/questions/4775722/check-if-object-is-array) – Alex K. Dec 05 '16 at 13:27
  • @deceze so there is also no way to check if an object is a class or an old school constructor. – Niels Dec 05 '16 at 13:30
  • Arrays are object, because everything in JS is object, so your can easily mark you array with your custom array flag, by ducktyping. Please check this example https://jsfiddle.net/tfgn6xzw/ out. – Marek Nowaczyk Dec 05 '16 at 13:30
  • That's a different question, and there's no fundamental difference between both. There are some subtle detailed differences, but nothing you typically need to worry about in everyday code. What do you really want to know? – deceze Dec 05 '16 at 13:42
  • @deceze Just curious if there is a way to see if an object is a class? – Niels Dec 05 '16 at 13:46

1 Answers1

1

You can detect if a variable is an array by using Array.isArray(yourArray).

ggradnig
  • 13,119
  • 2
  • 37
  • 61