Split the array into parts
var codeGroups = []; for (var i = 0, len = productCodes.length; i < len; i += groupSize) { codeGroups.push(_.first(_.last(productCodes, len - i), groupSize)); }