DEV Community

Discussion on: Javascript - Object is loopable too??

Collapse
alserembani profile image
Atif Aiman Author • Edited on

Some API, they prefer putting keys as something that represent the object, such as this

{
  "Atif": {
    age: 11,
    pref: true,
  },
  "Aiman": {
    age: 21,
    pref: false,
  },
}
Enter fullscreen mode Exit fullscreen mode

This way, backend can do a better indexing for more data processing. Though I am somewhere 85-92% agree of what you said, some of them had their reason. Though supposely when dealing with API to the frontend, I do favours array of objects instead.

Cheers 😎

Collapse
chadnaz profile image
Chad Naz

Good point. The only apis that return object of objects are old, outdated, and or not maintained in my experience. Which backs up your point - old technology might have needed faster indexing on the backend doing this but now a days just gimme the damn array. 😁