Use the “%” operator
Here we use the “%” operator to be able to do division and remainder. We will divide the remainder by 10 to get the last digit.
Use Array.pop() method
In this way, we will use the Array.pop() method to get the last digit of the number. You must know how this function works.
- Array: Array to remove element.
First, we will convert the number to a string and use the string.split() method because this method will return us an array of string characters, so the input value is satisfied with the pop() function.
After we convert the input number to a string, we will use the split() method to split it into an array of single-digit numbers because we are not passing any value to the function. Finally, we use the pop() method to remove the last element of the array of numbers and return it, rendering it to the screen like the output image above. Hope this is helpful to you.
Maybe you are interested:
Name of the university: PTIT