Question: I've got small problem in understanding "in" operator in JavaScript.
Why can't I go to the `if` block in example below? How do I do it?

```
var ar = [];
var a = 4;
ar.push(a);

if (a in ar){
    console.log("in if");
}

console.log(ar);
console.log(a);
console.log(typeof(ar[0]));
console.log(typeof(a));

```

Answer: 
The `in` operator tests whether the given property name exists in an object, it doesn't search the values. `a in ar` will be true if `ar[a]` exists. In your example, `ar[0]` exists, but `ar[4]` doesn't, so `a in ar` is false.

To search values in an array, use the `indexOf` function. It returns the array index of the found element, or `-1` if the value can't be found.

```
if (ar.indexOf(a) != -1) {
    console.log("in if");
}

```
If you are using in with Array you should use index/key and not the value.
Below will have the if condition true.

Ex: 

```
var ar = [];
var a = 4;
ar.push(a);
if(0 in ar){
  console.log("in if");
}

```

You can use property name when working with object.
Ex: 

```
var student = {name: "John", lastName: "Cena", age: 30};
if(name in student){
  console.log("in if");
}

```