I have an array of objects.
Whatever may be the size of this array, I need to ensure the size of the array as nn using a default object.
function fillRemaining(arr, n) {
var defaultObject = {'id' : 0, 'name' : ''};
var temp = 0;
while(arr.length + temp < n ) {
var template = $.extend({}, defaultObject);
template.id = new Date().getTime();
arr.push(defaultObject);
temp++;
}
}
This is what am doing now. Is there a better method to doof doing it?
Note: Am using lodash.