I was going to give a comment similar to Simon's till I saw his.
To add,
Objects can be simply referred to as key:value pairs for variables. They have no order exactly, so accessing the variable values, you'd need the keys.
In the json data in Simon's code, key:value would be
"child": "books # volumes"
where "child" is the key. This is the same method applied for the items such that key "items"'s value is an array which contains many objects.
The concept of array is that it contains ordered values such that the keys are the indexes (starting from 0). You access object values with variable.key while array values are with variable[index].
The forEach method applies your specified function to every value in the array. That's the reason you are able to display all search results.
If I understand it correctly, the object is nothing more than just storing unordered pairs. Key are usually strings, while values can be literally anything. And to use them, I'll have to add key next to a variable which in my post example happens to be items
Basically, object stores key:value and array store object.
If this is how the object works, then I can say with confidence that I know what object is and when to use them. (At least when working on an API)
I was going to give a comment similar to Simon's till I saw his.
To add,
Objects can be simply referred to as key:value pairs for variables. They have no order exactly, so accessing the variable values, you'd need the keys.
In the json data in Simon's code, key:value would be
"child": "books # volumes"
where "child" is the key. This is the same method applied for the items such that key
"items"
's value is an array which contains many objects.The concept of array is that it contains ordered values such that the keys are the indexes (starting from 0). You access object values with
variable.key
while array values are withvariable[index]
.The
forEach
method applies your specified function to every value in the array. That's the reason you are able to display all search results.I hope this helps too.
I love this explanation too!
If I understand it correctly, the object is nothing more than just storing unordered pairs. Key are usually strings, while values can be literally anything. And to use them, I'll have to add key next to a variable which in my post example happens to be
items
Basically, object stores key:value and array store object.
If this is how the object works, then I can say with confidence that I know what object is and when to use them. (At least when working on an API)
Yes, you're right : )