0

I have a string var x = 2019-02-14T21:06:06.400Z

Another string y = 2019-02-14T21:06:06.44500Z

I need to remove content after the dot i cant slice it because the dot might come after 4 or 5 or 6 or n characters

3 Answers3

0

Use split:

 

let [beforeDot] = "2019-02-14T21:06:06.400Z".split(".");
console.log(beforeDot);
Jack Bashford
  • 43,180
  • 11
  • 50
  • 79
0

You can use .split() in conjunction with an array access by index.

Example:

"2019-02-14T21:06:06.44500Z".split('.')[0]
Hybrid
  • 6,741
  • 3
  • 25
  • 45
0

A simple solution.

const strIn = "2019-02-14T21:06:06.44500Z";

const index  = strIn.indexOf(".");

const strOut = strIn.substr(0, index);

console.log(strOut);
Damien
  • 1,582
  • 1
  • 13
  • 24