Access an array in reverse in Javascript
Access an array in reverse. Consider the array in the code block below - const nums = [1, 2, 3]; Accessing the array is easy enough. console.log(nums[0]); console.log(nums[1]); console.log(nums[2]); /* 1 2 3 */ But, what if you want to access the array from the last element? Use pop We have seen one of the ways to do that using pop. console.log(nums.pop()); console.log(nums.pop()); console.log(nums.pop()); /* 3 2 1 */ But, this changes the array. console.log(nums); // [] Use slice If you want to just access the array from the last element, but not change the array - ...