0

This is my current attempt which is not working:

  const word = "abcd123";
  const filteredNum = word.split("").filter((e) => Number(e) !== NaN);
  console.log(filteredNum);
Avi
  • 1,049
  • 1
  • 5
  • 16
Abel
  • 43
  • 4

2 Answers2

1

Try this:

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

console.log(result);
naveen
  • 53,448
  • 46
  • 161
  • 251
manbearpig
  • 143
  • 1
  • 7
0

using isNan() function

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