Quick actions

cmd+k|ctrl+k

Navigation

Languages

Remove underscore from string

Snippet info

Language

JavaScript

Visibility

public

Author

onifademola

Created

2022-01-07T11:15:54.918599Z

Updated

2022-01-07T11:15:54.918599Z

const word = "Poured Milk 2";
// console.log(word.indexOf("_"));


const reverseString = str => {
    return str.split("").reverse().join("");
};

const reword = str => {
    const reversedString = reverseString(str);
    const indexOfLastUnderscore = reversedString.indexOf("_") + 1;
    const subWord = reversedString.substring(indexOfLastUnderscore, str.length);
    return reverseString(subWord);
}

console.log(reword(word));
console.log(word.includes("_"));


INFO