Question: Is there some nicer way how to convert 0 to 1 and vice versa in an array in JavaScript than going with for loop and converting it as described [here](https://stackoverflow.com/questions/2411023/most-elegant-way-to-change-0-to-1-and-vice-versa), ie:

```
var variable1 = [0,1,1,0,0];
var final = []

for (var i=0; i<variable1.length; i++) {
final[i] = 1-variable1[i] 
}
//1,0,0,1,1

```

Something similar to Python's:

```py
[1-i for i in variable1]
# [1,0,0,1,1]

```

Thanks.

Answer: 
If you can create a new array, I'd use `.map` instead:

```js
var variable1 = [0,1,1,0,0];

const final = variable1.map(n => 1 - n);
console.log(final);
```
```js
var variable1 = [0,1,1,0,0];

var final = variable1.map(v => v ^ 1);

console.log(final);
```

It is also looping. but I think this code is more readable.