If we create an array of objects using new Array(len).fil({}); and then add a key in any of the objects, it gets reflected in all the 3 objects

后端 未结 1 1972
孤城傲影
孤城傲影 2021-01-24 06:15

If we create an array of objects using new Array(3).fill({}); and then add any key in any of the objects, it gets reflected in all the 3 objects.

I made an array of obje

相关标签:
1条回答
  • 2021-01-24 06:42

    You put the same object at 3 different places. It's still the same.

    If you want 3 different objects, you may do this for example:

    const arr = new Array(3).fill().map(()=>({}));
    
    0 讨论(0)
提交回复
热议问题