References

String.padStart()

Leírás

A szöveg eléjéhez ad annyi karaktert, hogy a hossz megadott legyen.

Szintaxis

padStart(targetLength)
padStart(targetLength, padString)

Példa

const str1 = '5'
 
console.log(str1.padStart(2, '0'))
// Expected output: "05"
 
const fullNumber = '2034399002125581'
const last4Digits = fullNumber.slice(-4)
const maskedNumber = last4Digits.padStart(fullNumber.length, '*')
 
console.log(maskedNumber)
// Expected output: "************5581"
in this article
back to top