How to return a list of posts/comments and so on — an object or an array?

The situation when the API arrives, for example, the list of comments. The vast majority of tutorials make simple - array objects. But I noticed that many real-world applications return the data object, where the key is the aydishnik, and the value of the content itself.

What are the advantages of this method? Is it worth doing also?

ADF. It seems that the source of this trend https://firebase.googleblog.com/2014/04/best-pract...

Googol believes that arrays are evil.
March 12th 20 at 08:09
1 answer
March 12th 20 at 08:11
Solution
without any difference, depends on the task.
More interested in why it returns object. Perhaps there is a reason. Tasks are the same in both cases. - josiah65 commented on March 12th 20 at 08:14
@josiah65if for some purpose you want a quick search on ID, it makes sense to return the object with the right key. - maryam45 commented on March 12th 20 at 08:17
It seems that the source of this trend https://firebase.googleblog.com/2014/04/best-pract...

Googol believes that arrays are evil. - josiah65 commented on March 12th 20 at 08:20
@josiah65, is a special case hairbase. - maryam45 commented on March 12th 20 at 08:23
@maryam45, reddit not uses ferbas, but also returns the data object. - josiah65 commented on March 12th 20 at 08:26
@josiah65, so I kind of write on the white Russian: depends on your needs. the functionality is somehow tied to the keys - use objects that are not tied - we use an array.

you have the same argument of "that's they use, so it is stylish/fashionable/youth". - maryam45 commented on March 12th 20 at 08:29
@maryam45, I do not see scenarios when it may be "tied to the functionality". Can you give an example?

The pros I see in the other - lack of mutations of the data array in codebase, easier and faster access to data. It's probably not all that I'm asking. - josiah65 commented on March 12th 20 at 08:32
@josiah65, well, look on the exhaust of an IPA redit: in addition to the requested data directly there are still a lot of sluzhebny. so the exhaust is as the object (lugemine described once, the data are an array in some field).
if you do not need, it is easier to send an array of objects. - maryam45 commented on March 12th 20 at 08:35

Find more questions by tags API