Let's talk about removing some elements. So once again, I'll define foo. And it now has five elements. And then when I call foo dot splice, I'm passing it here two arguments. The first argument is the position of the position in the array, I'd like to perform this operation, as I'm saying, starting at position three, which to us is position four, because it's zero base. So for example, letter A is position zero, B is one, C is two, and d is three.
So we're starting with letter D, and then we pass it a one as the second argument. The second argument is a number of elements we'd like to remove. So I'm saying starting at position three, which is really the letter D, remove one letter, or one element, which in this case will be d. so this will return an array with the with the letter D in it. And that's exactly what I get. I get an array which has one element, which is the letter D. And if I inspect foo, I see that foo is now missing D, we removed one element from the array. Let's look at Another example.
So once again, I'll define foo. And it's got five elements again. And then now I'm going to call splice and pass it two arguments, three and two. So I'm saying starting at the third index, or the letter D, remove two letters. So now I'm going to get an array back with two letters, I'm going to get an array with letters D, and E, and that's going to remove them from the array. So execute that.
And I do get D and E back. And when I inspect foo, I get ABC because I removed DNA. So the main point here is that the syntax for removing elements is the first argument is the position at which you'd like to start working and the second argument is a number of elements to remove. Now, there's one thing I like to point out about removing elements is that we can start from the end if we'd like. So here are redefined foo. And then I'm now I'm passing it a negative number I'm seeing starting to count backwards three from the end and remove two elements.
So if I count backwards three, I get a DC. So starting at C remove two elements, so I should get an array with two elements in it contain illiteracy and D. And then the array should be missing those two letters. So I'm going to execute that. I get the array back with two elements. And then when I inspect foo, I'll see that C and D are missing. We just have A, B and E. So we can start backwards from the ray by passing a negative number.