Inserting a space at a specific index of a string – JavaScript

By using slice() method :

Explanation :

1. s = "12:40:22AM"
2. indexPosition = 10 - 2 = 8
3. result = 12:40:22 + " " + AM = 12:40:22 AM

Leave a comment