reverse Array Method | JavaScript Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
using the array reverse method you can as the name says it reverse an array meaning that the first element will become the last and the last will become the first and also the middle ones will reverse though obviously let's see how that works in code we have a numbers array which has the numbers from 1 to 5 and we're going to call the reverse method on this array and now we for console dot log if you're logging the numbers we get 5 4 3 2 1 so the reversed array keep in mind that this changes the original array if you don't want to change the original array you can store the new array and create a shallow copy of this array using the concat method and now you can see that the numbers are rate is the same but if your login the new array also we get the second array being reversed or you can use the spread operator instead of the concat and now it basically the same thing you're creating a new array and you're reversing the elements inside the array another use case for this method is if you want to reverse the characters inside of a string so let's remove this clear the console and now let's create a string which will say curling is fun and let's reverse this thing how we're going to do that is let's store it in another variable the result we're going to split the string in an array of characters providing an empty string here we're going to use the reverse method to reverse that array and then we can use the join method he'll join back the array inside a string and now we for console that logging the result we will get this string which is reversed that's it for this tutorial I hope you liked it and I'll see you in the next one bye [Music]
Info
Channel: Florin Pop
Views: 5,023
Rating: 4.9689922 out of 5
Keywords: javascript, javascript tutorial, javascript tutorial for beginners, array method, javascript arrays, learn javascript, javascript array methods, reverse, reverse array, reverse array method, javascript reverse, learn reverse
Id: xnjYcyphOoA
Channel Id: undefined
Length: 2min 24sec (144 seconds)
Published: Thu Apr 02 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.