The following code forces both elements with identifier 0 set to - , although I want only one of them to be set to -1 . Am I just creating a link to a labelArray, or is it something else?
labelArray.sort(compare); valueArray = labelArray; valueArray[0] = '-1'; labelArray[0] = '-';
Any help is appreciated.
UPDATE (2019): It has been several years since I first wrote this post, and ES6 is used almost universally. So, I wanted to go back and add that instead of using the slice() method recommended in the accepted answer, you can instead use an array that destroys to create a copy:
valueArray = [...labelArray];
source share