简体   繁体   English

jQuery的深度复制对象数组属性值

[英]deep copy object array properties value with jQuery

Take a look at this snippet: 看一下这个片段:

$.extend( true, {}, { key: ["somevalue"] }, { key: ["anothervalue"] })

doing this I expect the produced object will contain a property called "key" which is an array and has 2 elements, eg 这样做,我希望产生的对象将包含一个名为“ key”的属性,该属性是一个数组,具有2个元素,例如

{ key: ["somevalue", "anothervalue"] }

Am I just giving the deep copy more than it can handle? 我只是给深层副本更多了吗?

Nop !! 不! The result will be a object containing key having value ["anothervalue"], you are basically overriding the "key" as you pass more objects in the arguments with key as "key" 结果将是一个对象,该对象包含具有值[“ anothervalue”]的键,基本上,您将在键中将更多对象传递给键为“ key”时覆盖“ key”

Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM