JavaScript the Basics for Beginners - Section 3: Arrays | Rob Merrill | Skillshare

JavaScript the Basics for Beginners - Section 3: Arrays

Rob Merrill, JavaScript Instructor

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
8 Lessons (45m)
    • 1. JavaScript the Basics - Arrays: Promo Video

      1:55
    • 2. JavaScript the Basics - Arrays: Intro

      4:27
    • 3. JavaScript the Basics - Arrays: Intro Lab

      4:15
    • 4. JavaScript the Basics - Arrays: Methods Part 1 Lab

      5:18
    • 5. JavaScript the Basics - Arrays: Methods Part 1

      4:19
    • 6. JavaScript the Basics - Arrays: Methods Part 2

      5:25
    • 7. JavaScript the Basics - Arrays: Methods Part 2 Lab

      6:54
    • 8. JavaScript the Basics - Arrays: Review

      12:39

About This Class

Course 3 - JavaScript Arrays

In this course you will cover: 

  • Array Syntax
  • Basic Array Methods
  • Complex Array Methods
  • course review

Through our whole JavaScript the Basics for Beginners course series you will find this is your one stop necessary to enter into the language of JavaScript. We are going to start from scratch and build up our understanding of the world's most popular programming language together. 

View JavaScript in action with whiteboard videos optimized for viewing on your smartphone. This is truly a course that you can engage with no matter where you are. Take your JavaScript eduction on the go! With whiteboard videos you get to visualize what JavaScript does under the hood. 

You can practice JavaScript in your web browser! Take advantage of Google Chrome developer tools to put the JavaScript you have learned during our whiteboard lesson into practice with further examples and challenges. This is our JavaScript playground.

Learning JavaScript is like learning a language. This course won't make a false promise of saying you will master JavaScript overnight. However, this course will immerse you into the world's most popular programming language. 

Each course will introduce you to something new in JavaScript :

  • JavaScript Syntax
  • JavaScript Building Blocks
  • JavaScript Best Practices
  • JavaScript Objects
  • JavaScript Arrays
  • JavaScript Regular Expressions
  • JavaScript Functional Programming
  • JavaScript Algorithms
  • JavaScript Data Structures
  • JavaScript ES6 Syntax

You'll finish this course with an understanding of JavaScript that will let you take a deeper dive into the language and possibly launch you into a new career as a JavaScript web developer.

Learning a new language can be difficult and even feel intimidating. JavaScript the Basics makes the the learning process feel accessible and welcoming!

Transcripts

1. JavaScript the Basics - Arrays: Promo Video: Welcome to Java script. The Basics. JavaScript is the most popular programming language in the world has been called the language of the Web Stack Overflow listed as the most popular deaf technology and get have numbers it as the top ranks language learning JavaScript will allow you to be a full stack developer or fund a specialty on the front end or the back end. With JavaScript, you'll be able to cope with front and frameworks like react and angular on the client side . And you can also cut on the back end server side with no Js and create databases with Mongo . DB JavaScript is a language, so it's going to take some time to learn before you can write poetry or a novel in any language, you have to first learn the languages alphabet, how to make words and see how others use it. To learn JavaScript. We're gonna look under the hood. This isn't just going to be an exercise in copying someone else's code to wind up with an application you don't understand. Everything we do will be visual in the form of a whiteboard lesson where you can really see how everything works and connects. If you are a visual learner, this is the course for you. This isn't about going 0 to 60 or zero to hero, because if you really are starting at zero, those courses leave you behind quickly. It's about learning. Understanding and applying is that you could build and create with JAVASCRIPT. Way will then follow our white board. Lessons into the lab way will enter into the Google Chrome software developer. Consul thistles are Java script playground. There is nothing you will need to download for this course. No special tools, no extra steps. Just Google, chrome, everything. You learnt the lesson we will then recreate in the lab together. I'll then give you a code challenge to recreate what we learned together and then we'll look together at a possible solution. Welcome to Java Script. The basics. Let's start speaking job script 2. JavaScript the Basics - Arrays: Intro : Welcome back to Java. Script. The basics In this section, we're going to be looking at a race. We will be looking at what makes up in array and what we can do with them. A raise our list. Like objects, they're used to store multiple values on a single variable specifically for storing sequences of values written as a list between square brackets separated by commas in Java, script and a raise. An object. But it is an object with some specific behaviour. Let's go ahead and create in a rape, just like creating our object. Except instead of curly braces, we use square brackets. Let's look at some code. We'll call this test scores and let's fill it with values. And upcoming lectures will discuss a few ways of adding values to erase, and a ray is a question of values. So in a raid test scores we can see the values of 70 to 84 68 92 74 each value in the arrays called an element. Each element has a numeric position in the array known as its index array. Indexes are really little more than property names that happened to be imagers. A raise do not start with one, but with zero of pro tip is that while humans usually start counting at one computer, start coming at zero. If you ever suspected someone of being a robot, just asked them to count to 10 and see where they start a raise typically contain an ordered set of information, like storing the debt of home runs for each player. An array is great for a list where all the data has the same description, such as a list of names, test scores, daily temperatures or recipe ingredients. Now let's talk about excess ing elements of an array. Remember toe access values on an object we had use dot notation and wish you put a dot in front of a property or brackets around the property name and enclosed in quotes. For a raise. We will only use brackets and index number, with no quotes running the number. Suppose you want to access the 34 home runs from the home run list. We would enter the name of the array home runs, and because the Element 34 is in the third spot, the computer counts that is to 012 toe access 93 from test scores will write off the array test scores and Index zero. If you wanted to grab the lowest daily temp in the fifth spot, we would write daily temp brackets before lastly. If we want to access the cookie butter, we will find it an index. One of the cookie array a raise are also untie popped, which means an array element, maybe of any type. If the situation warranted, we might want to have a fish tank, a rate to contain elements of a fish tank regarding what it is made of gallons. It holds fish it contains and water level status. However, you might see a little bit of a problem while this works. Accessing these elements by index isn't as intuitive a naming convention, so accessing them may be more helpful with descriptive properties that come with objects rather than indexes of a race. Let's go ahead and look at the same values. If we had created them in an object. If this was an object, we might find it more accessible by giving it properties whose names make accessing the element more intelligible. Those aren't the only factors that come into play in discerning between using objects in a race. Both have properties and methods attached to them that will shape what data you place in them and what you use them for. Let's go ahead and close up this lesson by looking at the length property array. Dot length This'll Property is given to all Java script A raise and will be at your disposal. Let's go back to our original test scores array. This will give us the length of our array by simply adding dot length. Test scores dot length will give us five as you dive deeper into Java script and looked to iterated through Honore going through each value one at a time. This dot length property will be a big help. Thanks for taking a first look at Java strip to raise, and we'll see you in the lab for some challenges. 3. JavaScript the Basics - Arrays: Intro Lab : All right, let's get started with our lab and our lecture. We looked at the basics of a race. We saw that we can create an array by sitting a variable equal to two square brackets. Objects are created with two curly brackets and a razor created with two square brackets. Arrays are great for storing similar values, such as names, results of a test or daily temperatures. They're also a typed, which means an array can contain all the different JavaScript primitives. Let's open up. Our consulate gets started. We're going to make some arrays, access at it and even at values to those same arrays. Let's go ahead and create an array of sports team. So we have our baseball team's equals. Dodgers, Giants, Mets, Yankees and Astros. All right, Your first challenge is going to be to add of value to the end of the array. If you can't think of a baseball team, feel free to put whatever you want there. Your second challenge is going to be to turn the Giants into a different team in the array because I'm a Dodgers fan and I don't like the Giants hanging around my Dodgers. So let's go ahead and put another team. They're your third challenge is going to be to access the Dodgers value from their A and save it to the variable. My favorite team, your fourth and final challenge, is going to be the access the length of the array. So go ahead, put this video on pause and then we'll come back and solve this challenge together. All right. Hopefully, that wasn't too difficult. First, let's add value to the end of the array. We need to do two things. First, we need to ask. How long is the Array? We are going to jump to the raid dot length property, yet we can count five items in our A. Let's choose the value Cardinals to place in our array. So is this correct baseball teams six equals string cardinals? Nope. Remember, you want the Cardinals to be in the six spot, and we have to think like a computer thinks computer. Start counting at zero and because the rays start cutting at zero, if you put it at the index six, then it will be in the seventh spot. We need baseball teams than five. Within square brackets equals the string Cardinals. Just for fun. I'll go ahead and out another team, the Blue Jays making Seventeens. We should place it at Index six. Let's look at our rain now. Second challenge. Let's turn the Giants into a different team. Let's choose the Angels. What index for the Giants out in our A 01 They're the second spot, which is index one. So let's put the Angels in there. Baseball teams, Square brackets. One equals string of Angels. Let's go ahead and keep practising. Let's change the Mets into the Phillies as we can see that Mets are in the third spot, placing them at index to let's look at our array. Another time to check our progress. All right, 1/3 challenge. And this is a little twist, say the daughters value to a variable named my favorite team. We know that the Dodgers are index of zero of baseball teams. Now. We just assign that value to the my favorite team variable. Now, if we look, we see my favorite team reads Dodgers. Now, when we save this value to a new variable, we didn't remove it from the array. It stays there, and later lectures will learn some methods that actually delete or destroy those elements from the array for practice. Let's go ahead and save another value to a variable. Let's save the Angels to a variable called California Baseball. We can see that it is the second spot with an index value of one. So far, California baseball equals baseball teams at Index one. And when we checked the value of our new variable, we find that Angels is their value. That's all for now. We'll see you in the next lesson. 4. JavaScript the Basics - Arrays: Methods Part 1 Lab: Welcome back to Java. Script a raise. In this lesson, we're going to look at methods of a race and future lessons. We're going to dive into functions and methods for now. JavaScript a raise just like JavaScript objects are given methods that allow them to do work for us, like flipping on a light switch can fill up a room with light. So methods completed task while minimizing our effort. We're gonna look at the methods pop push shift and unsure IFT. These methods are different in the length property. If we look at them side by side pop push shift and unsure IFT, the parentheses giveaway that they are methods. While length is just a property, let's go ahead and look at our test scores array from a previous lesson. We haven't arrayed test scores with values 70 to 84 68 92. Let's try out the pop method on this array. This will pop off the last element in the array. Let's try it out. Test scores dot pop parentheses. Now let's look at our test scores are a 92 is gone from our original rate. The pot method will return the last value, but it will destroy it from the original array. What if we wanted to catch that value? How can we store that data? Let's think for a second what is good for storing data? We have something for that, right? Variables remember variables or containers that store data, so we need to create a variable to store the value that pops off the end of the array will create a variable called last test score. Then we'll execute the pot method on our test scores array. Our test scores array will now return values of 72 84. When we return the value of last test scores, we get 68. It's gone from the original array but stored in our new variable. Now let's look at the push method. We're going to use this toe out of value to the end of an array. Let's imagine that a new test has been graded and it needs to be added to the test scores array. But where do we put it again? We'll talk about this later when we dive deeper into methods. But this new test is your argument, and you place your arguments inside of them method parentheses, so test scores dot push, and we put 74 in as our argument. Now our test scores has a new score in its array way. Have 70 to 84 74 as our values. In fact, we discredit three more tests. How would we go ahead and put those in? Those three test scores are three arguments so will place them within the parentheses. Test scores push 30 to 96 in 84. That is going to give us an array with the values of 70 to 84 74 30 to 96 in 84. It's that easy to push multiple values at once. So we used the pop and push method to affect the end of the array. What if you want to access the values at the front of an array? We have two methods for that shift and un shift. The shift method will remove or delete of value from the front of the array. Let's go ahead and try it out on our test scores. Arrange This returns our previous array minus the 72 off the front of the array. Like the pot method this returns the value of an element and deletes it from the original array Mike in our previous example. Maybe instead of deleting or destroying a value from their ray alone, we want to save it. Sounds like we need another box to store it in a new variable, so we'll set the variable. First test equals test scores dot shift method. First test now returns to test out the front of the line. Now our test scores variable is getting pretty empty. Let's input some values in the front of our ray. We can do that with the unsheathed method. Let's go ahead and insert some scores of the front of their rate. Let's say that we have two tests. We need to add a 77. And in 83 just like the push method, we will put them in as an argument. So that's it. Thes methods will actually help set the foundation for something that you will run into later. As a JavaScript developer stacks and queues when you think stacks, think of a pile of books that you stack on top of each other. The last in is the first out. This is often abbreviated with L I F O. You're dealing with adding, and taking away from the end of an array sound familiar? That's the push and pop method. You will also work with cues. The principle of a Q is like a ticket line. First in is first out shorthand. Terminology is F I f o. You're dealing with adding, and taking away from the front of an array again. Sounds familiar. You are dealing with shift in UN shift methods on a race, but stacks and queues will be for another time. Thanks for joining me in taking a first look at a ray methods. Let's head to the lab and put these methods to use. 5. JavaScript the Basics - Arrays: Methods Part 1: All right, let's get started in our lab and our lecture. We learned about a raise. All JavaScript Aries come with a built in set of methods that we can use to do work for us in our past lesson. We dove into the array methods pop push shift in unsure ift, allowing us to add and take away from both the front and the back of an array in our lab. We're going to continue to put these array methods into practice. Let's go ahead and build our first array. Let's start off by declaring the variable shopping list and placing values within this square brackets of apples, pizza, chicken, mushrooms, oranges and beef time for our first challenge. Let's practice adding items at the front and the end of our array. So this means you're going to have to remember which are a method you use and how to insert your food value into the list. For your challenge, I would like you to put crackers at the front of our array and grapes at the end of our array. Go ahead and pause the video and give it a shot. Then we'll come up with a solution together. Hopefully, that was pretty straightforward. You should have used the on shift method to add crackers to the front of the array and push grapes to the back of the array. Remember, we're placing them within the parentheses as our arguments for a nxd eft and push. Now, if we look at shopping list in the console will see our mutated array quickly. Let's do our array dot length property. We learn from the previous lesson that is where we connect dot length to the end of our array. This returns the value of eight. Let's reinforce this one more time. However, instead of adding one item to the front end of the array, let's add two at the same time. First, we'll add Sir Russia and popcorn to the end of the list. Using the push method. Second will add lemonade and orange juice to the front of the list. Using the on shift method, let's check our length again. We get a value of 12 and we're checking the length property quite a bit because this will be a valuable tool as you deal with the rays in the future. All right, now let's look at removing items from our array here is a challenge. I want you to remove the first item and the last item from our array. Go ahead and pause the video and give it a shot. Then we'll come back and solve this together in a moment. All right, How to go? What methods do you use? Hopefully use shift and pop methods to make this happen? Let's go ahead and remove the first and last item from our ray to remove the item from the end. We simply use the method pop. It's removed the item from the front of the list. We simply use the method shift. Let's go ahead and quickly look at our shopping list. Now let's check the length of our shopping list. It looks like it has shrunk by two. We saw that in doing this, that both shift and pop return a value. When we use shift in pop, we destroy those elements from our original array, a razor immutable in which you can change their contents. But when we use those methods, there's an opportunity to catch them. As we saw in a previous lesson, let's practice capturing those values. Let's imagine that we're at a grocery store. Let's imagine. Our friend Sarah wants to grab the first item from the West, and our friend Phil wants to get the last item for my list. Will create a variable called first item Sarah and will sign it. The value of a shopping list dot shift method will create a variable called Last Time Phil , and we'll send it a value of shopping list dot pop method. Let's look at each of their names in the consul to make sure that they have returned the correct vice. Finally, let's close by looking at our A one more time and getting its length. All right, that's it for your first journey into a ray methods. In our next lecture, we're going to take a deeper dive into a ray methods and discover more things that they're capable of dealing. See then 6. JavaScript the Basics - Arrays: Methods Part 2: All right, welcome back to Java. Script. The basics. In this lesson, we're going to continue to dive into Java script array methods Again, array methods are gives from Java script available toe all array objects in JavaScript. Last lesson. We looked at pop push, shift and on shift. In this lesson, we're gonna look at the array methods. Can cat reverse and slice? So let's get started. We'll begin with the array method. This method. What's this joint to a race together? So to illustrate this, we're going to have to build to erase. Let's create a big dog and little dog array within the Big Dog array will add a golden retriever, a ST Bernard German shepherd and a Bernese mountain dog. Then we'll create a little dog array and fill it with a terrier, a wiener dog corgi and a Pomeranian will declare a variable called all dogs and will sign it. The value of our big dog array and then the King Cat method and within the parentheses will place the argument of the little dog array. Let's look at what all dogs or turns notice The order there. Ray placed in the argument comes after the original Ray. Let's imagine that we had 1/3 array, a cat's array. I don't know very many kinds of cats, so we'll say Our cat array has an alley cat, a fraidy cat and a scaredy cat. No, let's start over and try. Arkan Cap Method again will declare a variable called Enemies will sign it the value of Big Dog, then the King Cat method with parentheses, and we'll place our arguments of little dog and cats within the parentheses as arguments. The result is similar to what we saw earlier. We just learned that we can fill up the can cap method parentheses with a number of a raise that we would like to add. It doesn't have to just be one at a time, but they will return in the order that they were put in. Let's look at another array method called reverse. This is going to take or array and switch the order because you aren't making an argument and inserting any values. There's no need to put anything within the method. Call. Let's look at our All Dogs array and use the reverse method. Let's declare a variable called smallest. First, we'll send it the value of all dogs and the reversed method. Now, when we look at what has returned, we see that the order has switched the small dogs air now in front. That's basic enough. Let's look at another way of moving elements around within an array. It's the sort method. The sort method sorts all the items of an array. The sort order can be either alphabetic or numeric and either ascending up or descending down by default. The sort method sourced the values of strings in alphabetical and ascending order. Let's do some work on our dogs array instead of deciding who goes first being based on size , let's try by name. Let's declare a new variable called Alfa Order and will sign it the value of all dogs and the sort method. When we look at our right now, it doesn't matter if you are a big dog or little doc, the order is determined alphabetically. Now let's look in a method that has a bit more complexity to it. Let's look at the slice method. Our slice method will take in two arguments. The first specifies the start of the slice, and the second specifies the end of the slice to be returned. Here's the catch. It returns the value of where the slice starts and all the values up to, but not including the second argument. So let's try this out on our All Dogs array. Let's declare a variable called slice of dogs and assign it value of all dogs and the slice method to fill its parenthesis. We're going to grab value starting at Index one, which is the second number in our array. Then we're going to grab the following values up to but not including the second argument in our slice method, which is our element at Index four, which is the fifth spot in our array. Slice of dogs now returns elements within the range that we asked for. Unlike shift and pop, this doesn't destroy the values from the original Ray. It simply returns them. If your numbers are negative, that means that we're looking for their position from the end of the array. Let's look at an example. No county from the end of the array doesn't begin with zero. Like when we start counting from the front negative three places us at the third element from the end, then up to, but not including the second argument of negative one. Let's look at one more use of the slice method. This is when we use just one argument. This is when you want to choose your starting point in an array and return everything that comes after it. Let's look at an example. All dogs sliced three is going to start Index three and return everything that follows it. Thank you for joining me into this deeper dive into a ray methods. If you can master these basics, you're setting yourself up to do some more sophisticated things with JavaScript programming in the future. We'll see you in the next lab, where we can put what we have learned into practice. 7. JavaScript the Basics - Arrays: Methods Part 2 Lab: All right, welcome back to the lab. In our lesson, we looked at the Cannes Cat Method, which adds two or more rays together to become one. Then we looked at the reverse method, which allowed us to reverse the order of the values in an array. We then looked at the sort method, which can be either alphabetic or numeric in either ascending or descending by default. The sort method sorts the values of strings in alphabetical and ascending order. Then we finished up with the slice method, allowing us to specify sections of an array that we want to return, starting with the first argument and leading up to but not including the second argument, you could imagine taking this slice out of an orange. The only difference is that when you take a slice of heaven orange, there's less orange leftover. However, taking a slice from the original rate does not mutate or change the array. It simply returns the slice. It was a pack lesson. Let's start putting it into practice. Let's start off by building an array together. We'll call it colors. So would declare a variable colors give it values of red, orange, yellow green, blue and to go and violent. Here is the first part of your challenge. First, I want you to create another array. Make sure that doesn't have any duplicate colors. Then I want you to add those to raise together into a new array with any name you choose. Go ahead and pause the video. Give it a shot. Then we'll come up with a solution together. All right, hope that went well. Let's go ahead and create another array of colors, so we declare a variable colors to and will give it black, white, brown and purple. What method did you choose to join the race? I hope you chose the King Cat method, so we'll declare a variable all colors and assigned the value of colors that can cap method filled with an argument of colors, too. If we check the value of our all colors array in the council, we should see that both the rays have formed one array. Let's do another can cat method. Here is your challenge. Go ahead and create one more array of color. This time, the colors could be the same. If you'd like, then had all the rays together like we did in our lesson. Go ahead and pause the video and give it a shot. Then we'll come up with a solution together in a few moments. All right, how to go? We'll go ahead and declare a variable colors. Three. We'll give it the values of red, white and blue. From there, we'll add all three of their raise together to form a new array. So we'll declare variable more all colors and a son of the value of colors in the comm cat method filled in with the array colors one and colors, too. All right. Hopefully, that was pretty easy review for you. Now let's do two more quick challenges. I want you to declare two variables. Reverse colors and which you reverse the order of all the elements in the array, all colors and alphabet colors in which you reverse the order of all the elements in the all array colors array. Go ahead and positive video, and then we'll give it a shot together in a moment. All right, did you use the reverse and sort method? Let's go ahead and solve. These together will declare a very well called reverse colors and a sign of the value of all colors and the reverse method then will declare a variable called alphabet colors and a son at the value of all colors on the sort method. All right, for Last challenge, we're going to implement this slice method. This is gonna take a bit more work. Let's make a new array called Weather and will give it the values of rainy, cold, chilly, snowy, cloudy, hot, warm and humid. For our challenge, I want you to return an array value to a new variable called Winter that captures all the winter values from the array. I also want you to return an array value to a variable called Summer, using the slice method, returning all of the summer values. Go ahead and positive video and give it a shot. Then we'll come up with the solution together. All right, how to go? Hopefully you got it. But if not, here's one approach that I would take. Let's start with capturing the winter weather. We can assume they're the elements. Rainy, cold, chilly, snowy and cloudy. We'll use this slice method on the weather, will declare a variable winter and ascended the value of weather the slice method, and then we've got to choose what we're going to fill in the slice method with the winter conditions aren't Index zero through index four. So what arguments are we going to put in our slice Method? Zero. Because we want to catch the item. It index zero, and our second argument is going to not be four because the second argument is up to, but not including that argument. So we're going to choose five as our second argument. Let's give it a shot there. We've captured our winter array. Now let's capture a summer array. We're going to want hot, warm and humid hot. Is that index five? So we'll start with that because the first argument will include the index we name. And because we want to go all the way to the end of the array, we won't have to enter in another argument. Let's look at our summer values and see what we get Perfect. Now let's do the same. But let's use negative numbers to accomplish the same task as we learned in our lesson. Go ahead and pause the video and give it a shot with negative numbers. All right How to go. Let's come up with a possible solution. Once you get a mental grasp of this concept, is should start to come to you. Naturally, we want to grab the same winter elements as before. So we start at the first item in our index. We count from the end and negatives. And I remember when we count from the end, we don't start with zero, but negative. We see that cloudy is the fourth item from the end of the array. But because we don't include the position of the second argument, we have to put negative three in that spot. No, let's go ahead and find the solution for summer elements. We'll start by declaring our summer variable and a son of the value of weather and the slice method. So we want to choose the first element of summer, which is at the negative three index. And because we want to go all the way to the end of our array, there is no need for another argument. Perfect. Well, that's it for this lab. Thanks for joining me as we took this deeper dive into a ray methods there are much more where this came from. Look forward to joining you in the next lesson. 8. JavaScript the Basics - Arrays: Review : welcome back to Java, stripped the basics in this lesson. We're going to review our raise section we've covered so far. We're going to cover a raise and their methods. We will do this in a quiz format. As with all our section reviews, if the lessons seemed easy to you, then you may not feel a need to take this review s. This lesson will not provide any new material will move slow and deliberate to reinforcement cereal. However, if your understanding could use a helpful exercise and refresher than this is the lesson for you. Let's start off with a refresher definition of a race. A raise. Our list, like objects there used to store multiple values and a single variable specifically for storing sequences of values written as a list between square brackets separated by comments . Our first question is in regards to how we declare an array which of the following choices will create an array option. A var equals and open and closing curly brace be var array equals open and closed square brackets. See far array equals the keyword function, followed by parentheses and a code block or D open and close square brackets with values separated by commas. Hopefully, this was an easy icebreaker. No need to pause the video. The answer is B and D. Opening and closing square brackets will create an empty array, as we see with Option, B and D will create an array filled with the values of the numbers. 1234 and five. Now let's move on to another question, given the following array of pet names Max, Oscar, Charlie and Sam How do we access the name Charlie? Go ahead and pause the video if you need to open up the chrome consul and try out the possible solution. When you were ready, resumed the lesson. The answer is C A. Will not work because you don't access items on an array object with the DOT notation, as we do with normal objects. B isn't valid because that would actually access the string. Sam. Remember, computers don't start counting with the number one. They start counting with the number zero max. Zero Oscar is one, and Charlie is too All right. Let's move on to ray. Methods. Methods and functions are covered in a further section of this course. The difference between a method and a function is strictly vocabulary. When the function is attached to an object which arrays are a type of JavaScript object, it is called a method. When it is not attached to an object, it is called a function. There is not a difference aside from that suppose were given the following array. What method would we use if we wanted to take an item off the end of an array? And what method would be used if we wanted to add an item to the end of the array? A. Numbers with the shift method Be numbers with the unsheathed method passing three. As an argument, See the push method with an argument of three or D pop method. Go ahead and pause the video to come up with the solution, then continue when you are ready for the answer. All right. To take an item off the end of the array, you would use the pop method. This would return the value of the number seven, and our numbers array would no have the values of 234 and six. If we wanted to add a number to the end of an array, we would use the push method with an argument of three. Our numbers array would know how the values of 2346 and three let's move on to our next question. Let's suppose we have an array of names. What two methods will be used to remove the first element of the array, and what method will be used to add an element to the front of an array visit. Option A. The Shifts method. Be the shift method with an argument of the stream Joe. See the UN shift method with an argument of the String Joe or D The unshaved method. All right, go ahead and pause a video. Try it out in the Consul. If you need Teoh, resume the video when you're ready for the solution. The answers are A and C to remove an element from the front of the array. We use our shift method. We don't pass to it an argument because we're not looking toe. Add to the array, but to remove from it. Next, see names are dot unsheathed. With the string, Joe will put an element in the front of the array. Because we're inserting. We need to have an argument which is why we would choose C rather than D. Let's move on to our next question. We have been given three. A race Which option will unite these two women and men Arrays in tow? One. Which options will unite these two women and men are raise in tow. One. Which option will put the men before women? Which option will put women before men and which option will add pets to the end of the array? Go ahead and come up with a solution and resume when you are ready for an answer. Both options A and D will unite the men and women arrays with the can cat. Method B doesn't work because it is the wrong keyword. An option C doesn't work because it is passing an argument with a string of women. Instead of the variable women that consists of our array and the elements within it. Option B will place the women's names before men because they can. CAT method is attached to it. Well. Option C will place the women's name after the men because they can cap method is attached to the men's array. Lastly, Option E will place our array elements in the order of women men, then pets. We can see that we can pass multiple or raise as arguments at once, as with men and pets, and they will join the new array in the order that the arguments were passed. Let's look at two more methods. Let's look at an array called Roy G Bit. We will set equal to an array with the values of red, orange, yellow, green, blue, indigo and violet. What method we use if we want to reverse the order of these colors of the rainbow. Also, suppose we wanted to arrange colors of the rainbow in alphabetical order. What method would be used to achieve that? Go ahead and give it a shot. Then let's look at an answer together. Letter B will reverse the order of our array as the method needed is reverse and not option . A reverse order if we want to sort our ray alphabetically way, don't need to pass any arguments regarding any sort of filter, because by default, sword will sort alphabetically. Let's close up this review by looking at one more method slice. This was probably the trickiest method that we covered from this review Let's start off with the definition of slice. The slice Method returns a show copy of a portion of an array into a new array object. It will return a new array while leaving the original array untouched. Let's go back to our Roy G. BIV array, which implementation of SLICE will return the values of red, orange and yellow. Go ahead and come up with an answer and resume the video when you are ready for the solution. The answers are A and E our first argument and the slice method is going to be our starting point. The string red is the first item in our array, also known as Index zero, in an array for Option E. We have a negative seven. The negative means that we count from the end, starting with one, not zero. This also places us at the string red. Our second argument is the zero based index at which toe end the extraction. While our first argument included the element at the current index are second argument is the elements leading up to, but not including the current index. So index three points to the string green. So we take all the elements leading up to, but not including the string green. Let's go ahead and close out with one last question again sticking with our current array. Let's return green through violet. Which options would allow us to do this? Go ahead and pause the video to find the multiple solutions and resume when you are ready for the answers. All right, Option A. Does not work because the first argument is index four, which is the fifth element. Blue, not green. So we have the wrong starting point. Option B does work when we present only one argument. That is the starting point of our extraction. Three is the element of the string green, and it will extract all elements after it. The elements we were looking for Option C works. Our starting point is that Index three has already discussed, and then we have our second argument of seven. Our last element of yellow is that index six. But the second argument of slice takes up to, but not including the second argument, so six wouldn't work, but seven ducts Option D does not work because negative three will place us at blue. Remember, counting from the end starts at one and not zero. Option e will also be the right solution, starting at negative four green and extracting everything that comes after it. Lastly, Option F works as well. Negative four gives us the right starting placement and extracts all the way to seven, as we discussed with options Seat. All right, that's all we have for now, in a review of a rave methods. Thanks for joining me and we'll see you in the next lesson.