Home > Blockchain >  use javascript split function twice
use javascript split function twice

Time:04-21

I have the following string:

12.1.20.1, 81.32.68.68:50321

however I need to make it like this:

81.32.68.68

Could someone help me out with this?

I've already tried to use split(",")[1] but I also need to remove the :50321

Thank you!

CodePudding user response:

If you can use the split function twice on it, you can do something like this:

console.log(
  `12.1.20.1, 81.32.68.68:50321`
    .split(", ")[1]
    .split(":")[0]
);

This gives just the IP address out.

81.32.68.68
  • Related