Search code examples
javascriptarraysperformancestring-formattingstring-parsing

Javascript convert time to brackets


I have a javascript string and I would like to convert them into like this:

08:00:00 -> [8,0]

07:30:00 -> [7,30]

14:00:00 -> [14,0]

16:25:00 -> [16,25]

i'm not sure how to go about doing this. what is the fastest and most efficient way to do this in javascript?


Solution

  • Try this:

    var timeArray = "16:25:00".split(":", 2).map(Number);