7
Objects are arrays in Javasscript? I have difficulty understanding how this is possible:
var obj = {
title: 'some value'
}
console.log(obj['title']); // some value
In my conception the use of square brackets is possible only in lists to pass a direct index or have an increment variable to go through all objects.
How is that possible? When I access ['title'] he walks all the Keys (Object.keys
) from object to find the requested key or goes straight to "index"?
I think this has been asked here before, I need to see if I can find the duplicate.
– Maniero
The use of square brackets is a matter of syntax. There’s no such thing as "only possible for such a thing". Each language does it one way. Python, for example, uses this for lists, tuples, dictionaries and strings.
– Pablo Almeida