var newNums= [1,2,3,4,5,6,7,8,9,10,11,12]; var result = newNums.map(function(el, i, arr) { return i % 4 < 2 ? arr[i + 2] : arr[i - 2]; }); alert(result);