var m = [1, 2, 3, 2, 4, 7, 6, 5, 9, 11, 3, 4, 5, 6, 5, 7], i = -1; var s = []; while(m[++i]) { if (m[i] < m[i-1] && m[i] < m[i+1]) s.push(i+1 + '=' + m[i]); } alert(s.join(', '));