admin管理员组文章数量:1314299
I need to make multiple objects of same element. I cant figure it out that which should I use between [] and {} to make my data structure.
I am not clear about the difference between [] and {}. I am using Angularjs
I need to make multiple objects of same element. I cant figure it out that which should I use between [] and {} to make my data structure.
I am not clear about the difference between [] and {}. I am using Angularjs
Share Improve this question edited Mar 16, 2016 at 8:27 Zibellino 1,4336 gold badges26 silver badges33 bronze badges asked Mar 16, 2016 at 8:18 n3018n3018 1291 gold badge2 silver badges12 bronze badges 4- What language are you using? – TheBigH Commented Mar 16, 2016 at 8:19
- could you just precise which languare you are using ? – xiawi Commented Mar 16, 2016 at 8:19
- 1 AngularJS is a JavaScript framework (read the tag) so chances are it's JavaScript indeed. – Zibellino Commented Mar 16, 2016 at 8:23
- I need to know what is the difference between using [] and {} to pass elements in the angularjs javascript controller – n3018 Commented Mar 16, 2016 at 8:25
2 Answers
Reset to default 5[]
represents Array
{}
represents Object
The advantage of using array is the ability to use native functions like forEach
, sort
, split
, splice
and more.
The advantage of using object is to getting easy way to find specific item from list of items.
For example, if you have a list of objects with unique ID
for each one
and you create object that contain them by ID
:
var list = {"123": {ID: 123, ...}, "456": {ID: 456, ...}}
Now you can find item by ID
without searching in all items for this ID
just with list[ID]
Use []
if you want an array a.k.a. a list of objects. Use {}
if you want to create a single object.
本文标签: javascriptwhat to use betweenandin AngularjsStack Overflow
版权声明:本文标题:javascript - what to use between [] and {} in Angularjs - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741963781a2407427.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论