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
  • 40,575
  • 10
  • 44
  • 74
0

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

Example:

"2019-02-14T21:06:06.44500Z".split('.')[0]
Hybrid
  • 6,236
  • 2
  • 23
  • 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 Asseya
  • 1,547
  • 1
  • 13
  • 23