Javascript passing arrays to functions by value, leaving original array unaltered

前端 未结 9 1824
不思量自难忘°
不思量自难忘° 2020-11-28 11:01

I\'ve read many answers here relating to \'by value\' and \'by reference\' passing for sending arrays to javascript functions. I am however having a problem sending an array

9条回答
  •  情深已故
    2020-11-28 11:33

    by default in javascript except objects and arrays, everything is copy-by-value but if you want to use copy-by-value for arrays: use [yourArray].slice(0) and for objects use Object.assign(target, ...sources)

提交回复
热议问题