javascript remove special first characters from string code example

Example 1: remove special characters from string javascript

var str = "Hello^# World/";
str.replace(/[^a-zA-Z ]/g, ""); // "Hello World"

Example 2: trim first character in javascript

let str = 'Hello';
 
str = str.slice(1);
console.log(str);
 
/*
    Output: ello
*/

Example 3: remove first char javascript

let str = 'Hello';
 
str = str.substring(1);
console.log(str);
 
/*
    Output: ello
*/

Example 4: js remove special characters

var desired = stringToReplace.replace(/[^\w\s]/gi, '')