var arr = [6, 7, 8, 9, 14, 15, 16, 20, 21]; var mas = []; for(var i = 0, j = 3; i < arr.length; i++, j-=1) { (j > 0) ? mas.push(arr[i] + '-' + arr[i+j]) : j = 3; i+=j; } alert(mas)