Okay, let's talk about adding elements to any position in an array using the splice method. So I've got full again with the five elements, and I'm going to call the splice method. And here I'm doing something a little bit different than we did before. The first arguments a position at which I'd like to start working on passing the number two, so that means the letter C, because A is zero, B is one and C is two. I'm passing in zero as a second argument. So what I'm saying here is don't remove anything, the number of elements, I'd like to remove zero.
And the third argument is letter X. And what I'm saying is add the letter x where we'll add it at the SEC at the position number two, where the letter C is, that's where I want to start working. So this should return an empty array. And it should add a little x right after C. So I'm going to execute this we get the empty array which we expect because when we say don't remove anything, then it doesn't know what to return it just returns an empty array. But if I inspect foo, we can see that the letter X has been added at the second position. So it's I didn't remove C. So C was index two.
But now index two is going to be letter X and everything is shifted to the right. So we've basically inserted an element into this array at position two. Let's try another one. So I'm going to redefine foo. Once again. It's got five elements.
And now I'm going to say food dot splice one, remove zero and add the letters x&y. So index zero index one is the letter B. So we're starting the letter B, we're going to remove zero elements, so it means we're going to get an empty array back. And we want to add the letters x and y. So we should wind up with an empty array back and then food should now be a x y BCT. So let's execute it.
We get the empty array, which is exactly what we expect. And then we get a x y BCD. So letters X and Y were inserted at position one, which is where B was, but now we've got X and Y position one and then x becomes one, y becomes two becomes three, and so forth. So we're kind of sliding everything over. So the main thing about adding elements with this splice method is that the third and the third argument is and on matters because you're telling splice what you want to add, and we and we can add as many as we'd like. So we could say, food and supplies one remove zero and then we can say X, Y, and Z. Hello.
And first, let me just reset food. So food equals Okay, so now we see what fool is but now if I do this I'm going to get a XYZ Hello BCD and so forth. And it's going to return an empty array. So it returns the empty array. And when I inspect foo, I get a XYZ Hello. So it inserted all of those elements into the array position number one, so we can we can insert as many as we would like in one shot, but it's it all comes down to the third argument, or fourth, fifth, six, however many to indicate how many elements we'd like to add to the array and the position at which we'd like to add them.