In which case we have to go for object in javascript? In which case we have to go for Array in javascript?
Asked
Active
Viewed 48 times
0
-
Possible duplicate of http://stackoverflow.com/questions/4441139/when-to-use-an-object-or-an-array-in-javascript? – Zee May 13 '15 at 07:09
-
It is not always one or the other, it can be both, like an array of objects. It depends. – elclanrs May 13 '15 at 07:09
-
possible duplicate of [What is the difference between an array and an object?](http://stackoverflow.com/questions/874205/what-is-the-difference-between-an-array-and-an-object) – Christina May 13 '15 at 07:10
-
An object is a key,value pair and an array is a list of data generally of the same type. If the contents of your data has different aspects to it such as name, address, age then go for object else if it is just a list of age or names then go for array. You can also have an object within an array or an array within an object. It is all dependent on the scenario! – wallop May 13 '15 at 07:11
-
Thank you for everyone who are try to help me.. – Gmv May 13 '15 at 07:28
1 Answers
0
If you you have collection of properties use object, because using object is straight for you can access the desired property by obj.propName
. In case of array you need to remember the index of property. If you have collection of objects use array.
For more detail
When to use an object or an array in javascript