You have 2 options:
javascriptconst getNumbersFromLeft = (num, left) => { return parseInt(num.toString().slice(0, left)) } getNumbersFromLeft(123456, 4) // 1234
javascriptconst getNumbersFromLeft = (num, left) => { let num_length = Math.floor(Math.log10(num)) + 1 if(left > num_length) left = num_length return Math.floor(num/(10 ** (num_length - left))) } getNumbersFromLeft(123456, 4) // 1234
Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.