![]() This is very useful when you want to get the last element of the array, and then you just have to use -1. If we have given -2, it will return only. This will start counting from the end of the array and slice it (not the beginning from the array). In the above example, we have added a single argument as -3. Let slicedArray = favoriteFood.slice( -3) Let's see how this works with the below example. This array slice returns a new array with □ and □.Īnother thing that we can do with the slice() method is that use negative numbers for arguments. In this case, it will grab only up to index 2. ![]() Instead, it only includes the elements up to that index. But it doesn't include the index when slicing the array.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |