Home > Software engineering >  How to remove any number characters from a string
How to remove any number characters from a string

Time:10-07

This is my current attempt which is not working:

  const word = "abcd123";
  const filteredNum = word.split("").filter((e) => Number(e) !== NaN);
  console.log(filteredNum);

CodePudding user response:

Try this:

const word = "abcd123";
const result = word.match(/\d /)[0];

console.log(result);

CodePudding user response:

using isNan() function

    let word = "abcd123";
    let filteredNum = word.split("").filter((e) => !isNaN(e));
    console.log(filteredNum);
    console.log(filteredNum.join("")) 

  • Related