Javascript: How to have value in string represented by %s and then replaced with a value -
i know stupid question.
i've had few years experience javascript 1 thing seems have skipped mind, head has gone blank , can't remember it's called , how go doing it.
basically i'm looking when have string variable such as:
var error_message = "an account exists email: %s"
and pass string somehow , replaces %s.
i sound idiotic, i'd appreciate / reminding!
thanks guys.
you use replace
method:
error_message = error_message.replace('%s', email);
this replace first occurance, if want replace multiple occurances, use regular expression can specify global (g) flag:
error_message = error_message.replace(/%s/g, email);
Comments
Post a Comment