Kenyon Kenyon - 2 months ago 9
Javascript Question

What do you call this kind of thing in JavaScript?

What do you call this kind of dictionary inside an array thing?

[{
id: 1,
name: 'Category 1',
children: [{
id: 2,
name: 'Subcategory 1'
}, {
id: 3,
name: 'Subcategory 2'
}]
}, {
id: 2,
name: 'Category 2',
children: [{
id: 2,
name: 'Subcategory A'
}, {
id: 3,
name: 'Subcategory B'
}]
}]


I understand that it is literally an array of objects, and how you would use it. I'm more interested in a conceptual/metaprogramming name for it.

So the ultimate question is, what would you technically call this, if you wanted to be as specific as possible while talking to another developer? Maybe a technical math term to describe it?

Thanks!

Answer

Edit: it seems like you are asking if there is a special name for "array of objects." No, there isn't, this is just a ubiquitous idea in programming in any language. I don't even know anyone who would call it a pattern even.

The point of an array is that it can hold more than one thing of each kind. The inner array is an array of objects. It's called children. Children is plural. This is correct.

The outer array holds just one object. Perhaps the programmer intends to add more objects later. Perhaps it's being passed to a method that expects an array. I don't know, and it's not possible to infer anything besides "an array of one object."

Those are the only things even slightly unusual I see with your example. For how objects can hold arrays and how arrays can hold objects, consult any Javascript resource.