 <p>Here's the first method that came to mind. Yes, it <em>is</em> ugly, but it seems to work:</p> <pre><code>function renderArray(_checkbox) { var output = [], rangeStart = 0; function outputCurrent() { if (rangeStart &lt; i - 1) output.push(_checkbox[rangeStart] + " to " + _checkbox[i - 1]); else output.push(_checkbox[i - 1]); rangeStart = i; } for (var i = 1; i &lt; _checkbox.length; i++) if (_checkbox[i] != _checkbox[i - 1] + 1) outputCurrent(); outputCurrent(); return "{" + output.join("; ") + "}"; } console.log(renderArray([1,3,4,5,7,9,10,11,14])); // logs "{1; 3 to 5; 7; 9 to 11; 14}" </code></pre> <p>Demo: <a href="http://jsfiddle.net/Jq2sQ/2/" rel="nofollow">http://jsfiddle.net/Jq2sQ/2/</a></p>