I need to get a number, knock the last number off and then return it as a number
ie given the number 12345, return 1234
is this the best way to do it:
let x = 12345
const y = x.toString().split('').slice(0, -1).join('')
const newNum = Number(y)
also is there a way to not do the const newNum
and then just convert it back to a number in the string above?
I need to get a number, knock the last number off and then return it as a number
ie given the number 12345, return 1234
is this the best way to do it:
let x = 12345
const y = x.toString().split('').slice(0, -1).join('')
const newNum = Number(y)
also is there a way to not do the const newNum
and then just convert it back to a number in the string above?
I need to get a number, knock the last number off and then return it as a number
ie given the number 12345, return 1234
is this the best way to do it:
let x = 12345
const y = x.toString().split('').slice(0, -1).join('')
const newNum = Number(y)
also is there a way to not do the const newNum
and then just convert it back to a number in the string above?
I need to get a number, knock the last number off and then return it as a number
ie given the number 12345, return 1234
is this the best way to do it:
let x = 12345
const y = x.toString().split('').slice(0, -1).join('')
const newNum = Number(y)
also is there a way to not do the const newNum
and then just convert it back to a number in the string above?
I need to get a number, knock the last number off and then return it as a number
ie given the number 12345, return 1234
is this the best way to do it:
let x = 12345
const y = x.toString().split('').slice(0, -1).join('')
const newNum = Number(y)
also is there a way to not do the const newNum
and then just convert it back to a number in the string above?
I need to get a number, knock the last number off and then return it as a number
ie given the number 12345, return 1234
is this the best way to do it:
let x = 12345
const y = x.toString().split('').slice(0, -1).join('')
const newNum = Number(y)
also is there a way to not do the const newNum
and then just convert it back to a number in the string above?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.