Home > Software engineering >  How can i wrap a string with dollar sign?
How can i wrap a string with dollar sign?

Time:11-17

I am looking ways to wrap a string for example i want convert string "student" to "$student$". How can i achieve that in javascript?

CodePudding user response:

You can make use of template literals like that:

const wrapIntoDollars = (string) => {
  return `$${string}$`;
}

console.log(wrapIntoDollars("student"));

  • Related