简体   繁体   中英

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: ["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"

Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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