Merge Hashes

Javascript doesn’t have standard function to merger hashes. We can do it like below.

var hash1 = {'us': 'USD', 'jp': 'JPY'};
var hash2 = {'cn': 'CNY'};

for (var key in hash2) {
    hash1[key] = hash2[key];
}

 

Leave a Reply

Required fields are marked *.


This site uses Akismet to reduce spam. Learn how your comment data is processed.

Top