Is there an efficient way to clone an object yet leave out specified properties? Ideally without rewriting the $.extend function?
var object = {
"foo": "bar"
, "bim": Array [1000]
};
// extend the object except for the bim property
var clone = $.extend({}, object, "bim");
// = { "foo":"bar" }
My goal is to save resources by not copying something I'm not going to use.
jQuery.extend
takes an infinite number of arguments, so it's not possible to rewrite it to fit your requested format, without breaking functionality.
You can, however, easily remove the property after extending, using the delete
operator:
var object = {
"foo": "bar"
, "bim": "baz"
};
// extend the object except for the bim property
var clone = $.extend({}, object);
delete clone.bim;
// = { "foo":"bar" }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With