Получилось вот так:
var getData = function(arr1, arr2) {
var result = [];
var length;
for ( var i = 0; i < arr1.length; i++) {
if (arr2[i] === undefined) {
continue;
}
result[i] = {};
arr1.length > arr2[i].length ? length = arr2[i].length: length = arr1.length;
for ( var j = 0; j < length; j++) {