Splice doesn't copy array of objects [duplicate]
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This question already has an answer here: How do you clone an Array of Objects in Javascript? 29 answers using splice(0) to duplicate arrays 3 answers In this plunk I have an example of an array of objects a that I copy with slice() to b . I alter one of the objects in a but it changes also b . Isn't slice supposed to copy the array, including its contents? I need a and b to have different pointers. Javascript var a = [{x1:1, x2:2}, {x1:3, x2:4}]; var b = a.slice(); a[1].x1 = 5; console.log(b[1]); this prints: x1: 5 x2: 4 回答1: From MDN: For