0

What is difference of "Array" & "Object" in JS. I know only that:

var variable=[1, 2, 3, "Array"]
var varibale1={Fist:1, Second:"Some String", Third:"Object"}
1

2 Answers 2

0

If you compare "Array" with "Object", you should see the following similarities and differences:

  • "Array" is subclass, or sub-prototype, of "Object". So "Array" inherits all features from "Object".
  • "Array" is not a new data type. "Array" and "Object" are sharing the same data type "object".
  • The "typeof" operator on an "Array" object returns "object".
  • The "instanceof" operator on an "Array" object matches "Array". It also matches "Object", because "Array" is a subclass of "Object".
  • An object of "Object" can have indexed properties using the same syntax as "Array" objects.
  • An object of "Object" is not an object of "Array".
  • An object of "Array" is also an object of "Object".

Source: http://www.herongyang.com/JavaScript/Object-Compare-Array-Object-Difference.html

Sign up to request clarification or add additional context in comments.

Comments

0

For beginners, it is just two different ways of organizing data. Arrays are ordered lists, whereas objects contain key-value pairs. This difference is important because when you want to access or set the data, for arrays you use indices like variable[0] to get the first item. For objects, however, you would have to do variable1["First"] or variable1.First

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.