We've now learned enough about arrays that we can look at how an array can help us simplify or solve a programming problem. I'm going to jump to sublime. And you may remember this exercise from a previous movie, where basically we want to use the date object, and then print to the console, the day of the week. And so we would get the day date object, then we would find out what the day is using the get day method. And then we use if else statements or a switch statement to go through and check the numbers and we're proud Sunday, Monday and so on. This one wasn't completely finished this example here.
Well, let's remove this if statement. And let's look at a different way we could solve this with an array. So first, let's create our We'll call it days of week. Instead of equal to, we use brackets. And then we start entering the values which are the days of the week. Also, we haven't done an array that contains string values yet but as you can see, that is entirely possible.
And then I put Monday as the first day of the week, but actually, according to the date objects Sunday is the first day of the week. All right, now we have an array created. Now let's look at how we would print out the day of the week. It is In the previous exercise, we had to do a bunch of if else statements or we had to do a switch statement. Well with an array, it becomes very easy because remember, the get day method of the date object returns a number and it's zero base what fits very well with an array. So we can simply do console dot log.
The day of the I think we set it this way. Today is then we're going to concatenate days of the week, that array and inside of the brackets we will put day close it with a semicolon, save it, and let's see how it works. I'm going to copy the file path. Jump out to the browser. Let's open the console. It says Today is Wednesday.
And indeed Today is Wednesday. So notice how we were able to apply the array to this problem. It shortened our code quite a bit and made it much simpler to read. And the reason it was easy to do is because we were dealing with some data that we had to make manageable and arrays can help us with data. It was simply a list of data, in this case, a list of days of the week, and so it fit very well into an array and really shortened the code that is required to solve this problem. Alright, let's move on to the next topic and learn some additional things about arrays.