Want more features on Pastebin? Sign Up, it's FREE!
Guest

merge js objects

By: a guest on Feb 7th, 2012  |  syntax: JavaScript  |  size: 0.19 KB  |  views: 51  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }
clone this paste RAW Paste Data