Question: Very simple question but I couldn't figure why the below code results in NaN in first index?

```js
    var arr = [1, 2, 3, 4];
    var result = arr.map(function(x) {
        if(arr[x] >= 2) {
            return arr[x] + 10;
        } else {
            return arr[x] - 10;
        }
    });

    console.log(result); // [-9, 12, 13, NaN]
```

Answer: 
Array `map` accepts parameter as `(item,index)`. In your case `x` is representing array element which will be 1,2,3,4 and so on. So arr[1] will be first element that is 1, but `arr[4]` will be undefined since there is no element present at the `fifth` index. You can replace `arr[x]` with only `x` or with `arr[index]` 

```js
var arr = [1, 2, 3, 4];
var result = arr.map(function(x, index) {
  console.log('Array element', x)
  if (arr[index] >= 2) {
    return arr[index] + 10;
  } else {
    return arr[index] - 10;
  }
});

console.log(result);
```
```
var arr = [1, 2, 3, 4];
var result = arr.map(function(val, indx) {
    if(arr[indx] >= 2) {
        return arr[indx] + 10;
    } else {
        return arr[indx] - 10;
    }
});

```

You need to use index not value 

or you can do it like a pro 

```
 const result = arr.map((val, indx) => {
      return  (val >= 2) ? val+10 : val -10       
    });

```