0

How do I merge these two objects. The merge function won't combine them.

var $exID = $('#exDIV input');
var values = {};
$exID.each(function(i, el) {
    values[$(el).attr("id")] = $(el).val();
});

var actionData = $.merge(values, { "tableID" : "exTable" });
coder
  • 6,111
  • 19
  • 54
  • 73
  • Related: http://stackoverflow.com/questions/171251/how-can-i-merge-properties-of-two-javascript-objects-dynamically – karim79 Apr 04 '11 at 02:16
  • What version of jQuery? Unless it's > 1.4, this won't work as in previous versions `$.merge()` expects true javascript arrays. – Alex Apr 04 '11 at 02:19
  • I am using 1.4.4. It wouldn't work for me. I think $.extend should do what I need. – coder Apr 04 '11 at 02:30

1 Answers1

1

You are dealing with two objects, not arrays. Use $.extend instead of $.merge.

Amadan
  • 191,408
  • 23
  • 240
  • 301
  • It's better to use `$.extend()`, but `$.merge()` will also work on objects in jQuery 1.4+. – Alex Apr 04 '11 at 02:23
  • It will work on *some* objects. Not all, since it is trying to treat them as "arraylike", AFAIK. In particular, the OP's example clearly does not work. – Amadan Apr 04 '11 at 02:30