Change the value of an array changes original array JavaScript

前端 未结 3 736
面向向阳花
面向向阳花 2020-11-29 13:41

The following code causes both elements from id 0 to be set to -, even though I want only one to be set to -1. Am I just creating a re

3条回答
  •  失恋的感觉
    2020-11-29 14:04

    Am I just creating a reference to the labelArray […] ?

    Yes, exactly. valueArray and labelArray still identify the same object, which hasn't been copied.

提交回复
热议问题