I have a javascript array like:
var arr = ['black', 'white'];
Now if I have a variable containing one of the element, how can I easily get the other? For example
var color = 'black';
var otherColor = '???'; // should be 'white', how can I get it?
I'm looking for the simplest/cleaner way possible.
Also, I don't want to mutate the original array.
Thanks
ANSWER
What about:
var otherColor = arr[1 - arr.indexOf(color)]