Javascript – remove the last digit from a number

pay, numbers, digits-2662758.jpg

In this brief explanation, we will learn how to remove the last digit by using basic math

So the first and only step is to divide a number by 10

const number = 111;

const stripped = (number / 10) | 0;
//11

stripped is now 11.
There you go, job done

In case you have a string we will add parseInt

const number = "1423";

const stripped = (parseInt(number) / 10) | 0;
//142

And there you go, could not be simpler. God Speed!

Leave a Comment

Your email address will not be published. Required fields are marked *