Replacing all special characters with their ASCII value in a string - JavaScript

We are required to write a JavaScript function that takes in a string that might contain some special characters. The function should return a new string should have all special characters replaced with their corresponding ASCII value

Example

Following is the code −

const str = 'Th!s !s @ str!ng th@t cont@!ns some special characters!!';
const specialToASCII = str => {
   let res = '';
   for(let i = 0; i 

Output

This will produce the following output in console −

Th33s 33s 64 str33ng th64t cont6433ns some special characters3333
Updated on: 2020-09-18T12:41:12+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements