简体   繁体   中英

Replace the numbers with *

How to replace the last two digits with asterisks using JavaScript Example: console.log(Math.random()) // 0.6334249899746089 || 0.63342498997460** console.log(Math.random()) // 0.6334249899746089 || 0.63342498997460**
I gave you as an example random

To replace the last 2 digits with some characters, firstly convert it to a string and then, using the slice() method, append the characters. You can read more about the slice() method in its MDN Documentation .

let numberAsString = Math.random().toString(); //your number as a string
let result = numberAsString.slice(0, -2) + '**'; //cut and append your asterisks

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM