Combine two associative arrays together - Node.js Array

Node.js examples for Array:Associate Array

Description

Combine two associative arrays together

Demo Code

/*/*from w  w  w. ja  v  a 2s .c om*/
 * combine two associative arrays together
 * http://stackoverflow.com/questions/929776/merging-associative-arrays-javascript (modified)
 *
 * @param {Array} arr
 *          Array object
 *
 * @return {Array} new combined associatibe Array
 *
 */
Array.prototype.combine = function(arr) {
    for (item in this) {
        arr[item] = (arr[item] != undefined)
            ? arr[item]
            : this[item];
    }
    return arr;
};

Related Tutorials