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
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
Use split
:
let [beforeDot] = "2019-02-14T21:06:06.400Z".split(".");
console.log(beforeDot);
You can use .split()
in conjunction with an array access by index.
Example:
"2019-02-14T21:06:06.44500Z".split('.')[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);