You can use merge instead of extension:
var config = { "numeric": false, "keycode_whitelist": [ 37, 39, // Left, right 9, // Tab 17, // Ctrl 116 // F5 ] }; var custom = { "somevalue": "some other things", "keycode_whitelist": [ 1, 2, 3 ] }; var newopts = $.extend({}, config, custom); newopts.keycode_whitelist = $.merge(custom.keycode_whitelist, config.keycode_whitelist);
Demo: http://jsfiddle.net/3Q4cF/2/
Update:
To combine each individual array:
$.each(config, function(key, obj){ if($.isArray(obj)) { if(custom[key]) { newopts[key] = $.merge(config[key], custom[key]); } } } );
http://jsfiddle.net/3Q4cF/5/
source share