Within objects, just like arrays, you can hold string values, you can have no values, and you can
also have boolean values.
So Boolean values are the ones that can either be true or false.
So that's the two values for the boolean value.
And then those can be added in.
And as well within the object you can have an array and the array can have multiple pieces of data.
So if you want to extract the information contained within the object, you'd have to loop through the
data.
We saw that if we can select the main object and then the property name and that's going to return back
the value.
We also saw in the last lesson that we can output values within the dot notation as well as the bracket
notation.
And there's more information about this over at the Mozilla Developer Network.
And also, if you are using the bracket notation, if you have an object within an object in order to
return back that information, you could set it with the two property names.
So let's provide one more example of that.
So this is going to be an object and it will be just the courses.
And then each one of the courses here is going to also be an object.
So this can be the name of the course.
So in order to return back the name JavaScript of the course and also let's add in some more.
Values here, so just say length and 15 for the length.
So if we wanted to return back the length of value, you can go ahead and pause the video and try out
this example by returning back the value of the courses length and then I'll walk you through how to
do that as well.
So select the person, the object name and using the bracket notation, let's select the courses and
that's going to return back that object.
And then within the object that's contained within the object, let's return back the value of length
and that's going to be 15.
And we can also get the value for the property name of name and that's going to return back the course
name.
So also within here, you might also have multiple courses, so that would be an array and wrapping
it within an array.
Let's now return back that courses and because we have an array in here, this is going to represent
an array of items.
We can reference the index value of the item that we want to return back, and then also if we want
to see the length, we can specify it that way.
So these.
Can get fairly lengthy, depending on how much data you've got within the object, and the nice thing
about it is that if you have multiple items within an array, you can also if they they should be structured
the same way so that it's easier to iterate through them.
So let's go ahead and we're going to create and add in a few other courses.
So there might be an HTML course and the length of the HTML might be 10 and the success course might
be 20 in length.
So now we've got a more a really fairly complex object.
And usually if you do want to output the content, if you want to work with the courses, you can loop
through and you can get the values of the contents of the course by specifying and creating a new variable
name for the courses.
So I'll just set that up and then selecting person.
And courses that's going to turn back the courses within and courses object, and that will allow us
to loop through the courses and return back each one of the courses you can use for each loop to loop
through them.
And then within the for each loop, we can specify a course name.
We can also get the index value and using the arrow notation.
And just as we would with any other array, we can loop through and we can get all of the course information.
And then once the course information has been selected within a course variable name, you can output
each one of the course values by using something like course name.
And that will reference the current course name as it loops through in order to get the property values
within an object.
You can also create a loop for that.
So looping through the property values and let's select the property and objects.
And we need to specify the object, which is person, and will console out what we get back for property.
So here we have a comment about these console messages so that as we loop through the object information,
so the object, which is person where returning back each one of the property names as prop and logging
it out into the console, and that's where we get the first name, last name x1 x2 interests and courses.
And it doesn't indicate whether these are going to be arrays or other objects that are contained within
there.
It just returns back whatever the property name is, and then it's up to you to loop through and navigate
through to that property name to find out what's contained within that property.
You can also return back the keys of an object.
So if you just wanted to get the key values of an object, so let's use the object and look for keys
within the object.
And then within the parameters, specify the object and then you can log out keys in order to see all
of the keys of that current object, and that's going to be created and added into an array.
And then within this array, then you could loop through keys and use for each to loop through each
one and return back each one of the keys.
And in this case.
You can select person.
Key, and that will loop through each one of the keys that are contained within the object.
And output the response here, so we've got Lawrence Sparkasse, so one, two, so it's OK putting them
all according to the Keys, and then when it gets to the array within there and outputs that and then
the object that's contained within there as well, if you want to get the values, you can do a very
similar thing as we did with the Keys, where you can output the values of the object.
And instead of using keys, let's output the values of person and then log out whatever we've got for
values.
And I'll commentates the other console messages so that we're only returning back an array of whatever
the values are within each one.
So this is a way that you can access the values easily that are contained within the object and put
it within an array.
And then the same thing that we saw with the keys, you could iterate through each one of the values
because now it's within an array and output the value into the console or do any other type of calculations
that you want to do.
So this is actually just returning back the values so we don't have to reference the object and just
putting each one of the values.
So it's actually separated out from the object.
You can also get the entity entries that are within each one of the object items.
And let's create another variable, and this one, instead of values, is going to be object entries
and specify the object name there and that's the object that we're looking for and then output the entries
and let's put that to the console comment to the other ones.
So this way, what it does is it constructs an array of all of the properties that are within the object
and provides the property name as the first item within the index of the array and then the property
value as the second item.
And then that goes for all of the items that are within that array.
So once you've converted an object into an array, so either using the keys values or entries so you
can loop through it just as it would be a normal array.
So we saw that you can use the for each to loop through the array and then there's also a similar loop.
There's the for loop, which is similar to the one that we used to loop through the properties with
an object, and you can loop through it that way as well using the for loop.
So let's take the key value and actually just call it the array.
Of entries.
And this will loop through each one of the items assigning a value to the array and save again just
to remove it, so we see that we've got each one of the array items so we can list out the property
and then the value because we're using the entries.
So it's converted into an array.
So it's listing out the property, the value, property value, property value all the way down.
So go ahead and try to make and update your object information, adding in more complexity into it.
So checking out the different courses and adding in an array of objects of items there, loop through
it and output it with the key values and entries into the console and you'll be ready to move on to
the next lesson.
The lesson challenge.
Create an object loop to the contents of the object.
Add an array within the object has value, add another object within that object as a value as well.