SHARE
TWEET

merge js objects

a guest Feb 7th, 2012 51 Never
  1. Something like this,
  2.  
  3. var a = {en : 5,fr: 3,in: 9}
  4. var b = {en: 8,fr: 21,br: 8}
  5.  
  6. c = {}
  7. for(var k in a){
  8. if(typeof b[k] != 'undefined'){
  9.   c[k] = a[k] + b[k]
  10.  
  11. }
  12. else{
  13.  c[k] = a[k]
  14. }
  15. }
RAW Paste Data
Top