-3

Hi I'm trying to remove the letters and special characters from javascript.

Example:

var id = "Parameter[0].Category"

I only need the "0" from this. Thank you

Clark
  • 13
  • 3
  • 1
    Please show some effort. There should be plenty resources available to start and try to code this yourself. If you still have trouble to find a solution, show us what you have tried. – Lapskaus Jan 22 '21 at 11:38

2 Answers2

1

Try this

var numbers = id.match(/\d+/)[0];
console.log(numbers);

In general this is called filtering using regular expressions.

centralhubb.com
  • 2,141
  • 16
  • 14
0

If you want to filter out letters and special characters you can use regular expression in JS, like this:

id = id.replace(/\D/g, "")

You replace every (g option) character in your string that is not a digit \D with blank ""

Giovanni
  • 187
  • 1
  • 12