javascript - What is the faster way to convert an object with property value: "HH:MM:SS" to string "N Minutes"? -
i have hundred of objects construction like
{ moviename: 'xyz', time: '02:15:50' timeastext: null }
i need set timeastext
text "136 minutes" based on property 'time'. seconds should rounded up.
could point me out faster approach?
i tried 2 methods (demo); first using map
, , sec using plain for...loop
. can see demo plain loop considerably faster:
var out = []; (var = 0, l = arr.length; < l; i++) { var obj = arr[i]; var time = obj.time.split(':').map(number); if (time[2] > 0) { time[1]++; } obj.timeastext = (time[0] * 60) + time[1] + ' minutes'; out.push(obj); }
javascript
No comments:
Post a Comment