Q:

Write a JavaScript program to replace the first digit in a string (should contains at least digit) with $ character

0

Write a JavaScript program to replace the first digit in a string (should contains at least digit) with $ character.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

function replace_first_digit(input_str) {

  return input_str.replace(/[0-9]/, '$');
}
console.log(replace_first_digit("abc1dabc"));
console.log(replace_first_digit("p3ython"));
console.log(replace_first_digit("ab1cabc"));   

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now