json - Insert missing data using Lodash -
If we want to insert missing data, then what would be best to use the Lodash function? For example, our data
[{'time': '12: 00 ', position: true}, {' time ': '01: 00', status: true}, { 'Time': '02: 00 ', position: true}, {' time ': '03: 00', position: true}, {'time': '04: 00 ', position: true}, {' time ': 23: 00', status: true},]
and I would like to include it from 05:00 to 22:00
< Div class = "post-text" itemprop = "text">
var startNumber = 5; Var Endnumber = 22; Var step = 1; Var originalArray = [{'time': '12: 00 ', position: true}, {' time ': '01: 00', position: true}, {'time': '02: 00 ', status: true }, {'Time': '03: 00 ', position: true}, {' time ': '04: 00', position: true}, {'time': '23: 00', status: true} ]; Var getMappedItem = function (item) {return {time: item + ': 00', position: true}; }; Var newArray = originalArray.concat (_. Category (start number, end count + 1, phase) .map (getMappedItem)); // The new array does not include the combined array of unavailable data / you can now use _.sortBy () to sort the array with the function // to determine how to sort it // Example _.sortBy for (newArray, function (item) {// return parseInt (item.time.substr (0,2))}};
Comments
Post a Comment