How to replace values in a string, in JS

JavaScript: How to replace values in a string, in JS

You can use the replace() method to replace parts of a string with something. Here is an example:

  1.             let some_string = "Hello, world";
  2.              console.log(some_string.replace("world", "everyone"));

Hello, everyone
webdevetc profile pic
webdevetc

I am a 29 year old backend web developer from London, mostly focusing on PHP and Laravel lately. This (webdevetc.com) is my blog where I write about some web development topics (PHP, Laravel, Javascript, and some server stuff). contact me here.



More...


Comments and discussion about How to replace values in a string, in JS

Found this interesting? Maybe you want to read some more in this series?

Or see other topics in the JavaScript language

Or see other languages/frameworks:
PHP Laravel Composer Apache CentOS and Linux Stuff WordPress General Webdev and Programming Stuff JavaScript
Or see random questions

What is the difference between reference and primitive data types types in Javascript?

PHP Date commonly used formats

How to autoload helper files with composer?

How to remove .php from the end of URLs with .htaccess

What are Template literals (Template strings) in JS?

How to show a specific view file for certain error codes?

What are the SPL Iterators in PHP?

What kind of database field type should you (normally) use for foreign keys?

What are generators in PHP, and how do they compare to arrays?

How to find out what version of Laravel you are using?