Angular – Property ‘replaceAll’ does not exist on type ‘string’

angularangular10typescript

I want to use replaceAll in typescript and angular 10.

But I get this error: Property 'replaceAll' does not exist on type 'string'.

This is my code:

let date="1399/06/08"
console.log(date.replaceAll('/', '_'))

Output: 13990608

How can fix my typescript to show me this function?

Best Answer

You may solve the problem using RegExp and global flag. The global flag is what makes replace run on all occurrences.

"1399/06/08".replace(/\//g, "_") // "1399_06_08"