Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to replace word from string in javascript

var str = "Please locate where 'locate' occurs!";

str.replace("locate", "W3Schools"); //replace only replace first match from string
str.replace(/LOCATE/i, "W3Schools"); // i makes it case insensitive
str.replace(/LOCATE/g, "W3Schools"); // g replace all matches from string rather than replacing only first

document.write("<br>" + "replace:", res7);
document.write("<br>" + "replace with case insensitive:", res8);
document.write("<br>" + "replace all:", res9);
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript set file input value to null 
Javascript :: how to put background image in angular 11 
Javascript :: next js next/head head 
Javascript :: difference between parallel testing and cross browser testing 
Javascript :: single quote error in react prettier 
Javascript :: array remove element js 
Javascript :: jquery get link href value 
Javascript :: set nested state react hooks spread operator 
Javascript :: how to write tuples in elixir 
Javascript :: external button to fire dropzone.js 
Javascript :: how to push the get variables without page reloading in Jquery 
Javascript :: default error handler express 
Javascript :: switch c++ 
Javascript :: js get location search parameter 
Javascript :: visual code put quotes to each line 
Javascript :: readfilesync 
Javascript :: how to format money as currency string 
Javascript :: next js update 
Javascript :: instance use in_array in javascript 
Javascript :: js get all object styles 
Javascript :: how to get cwd nodejs 
Javascript :: node js get files in dir 
Javascript :: dictionary length javascript 
Javascript :: map object es6 
Javascript :: jquery scroll to div callback 
Javascript :: slide right jquery 
Javascript :: find word in javascript string 
Javascript :: process memory usage javascript 
Javascript :: jetbrains font vscode 
Javascript :: document.getElementById visual basic 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =