 <p>There are some logic errors in your original code (i.e. infinite loop). Fix:</p> <pre> function joinParameters(target, paramName) { var count = 1; var array = []; var name = paramName.concat(count); var value = target[name]; while (value != undefined) { /* typeof value will return "undefined". */ array.push(value); /* You need to increment 'count'. */ name = paramName.concat(++count); value = target[name]; } target[paramName] = array; } ... joinParameters(target, "x"); </pre> <p>Note this function call will add a new element <code>x</code> to <code>target</code>, <code>x1, x2, ..., x6</code> will still exist in <code>target</code>. In fact, this function doesn't take care of the <code>y</code> element, which I assume you want to "join" as well.</p> <p>For a more versatile function, the answer by <em>zachallia</em> should do the trick.</p>