# JavaScript isArray and thisArg Methods


[![s-l1600.jpg](https://cdn.hashnode.com/res/hashnode/image/upload/v1615147167990/6zalhYPvf.jpeg)](https://ebay.us/XfkRzX)

---
### *isArray* method
The `typeof` method does not distinguish between arrays and objects.

See the example below:

```js
console.log( typeof {} ); // object
console.log( typeof [] ); // object
```

The `isArray` method returns true if it is an array, false otherwise.

The syntax is shown below:

```
Array.isArray(arr);
```

See the example below:

```js
console.log( Array.isArray({}) ); // false
console.log( Array.isArray([]) ); // true
```

### *thisArg* method
Most array methods (`find` `filter` `map` ...) have the `thisArg` has an argument.

See the syntax below:

```
array.find(func[, thisArg]);
array.filter(func[, thisArg]);
array.map(func[, thisArg]);
// ...
```

> `thisArg` is rarely used and optional.

See the example below:

```js
const army = {
  minAge: 18,
  maxAge: 27,
  canJoin(user) {
    return user.age >= this.minAge && user.age < this.maxAge;
  }
};

const users = [
  { age: 16 },
  { age: 20 },
  { age: 23 },
  { age: 30 }
];

// find users, for who army.canJoin returns true
let soldiers = users.filter(army.canJoin, army); // between 18 and 26 
// => { age: 20 }, { age: 23 },

console.log(soldiers.length); // 2
console.log(soldiers[0].age); // 20
console.log(soldiers[1].age); // 23
```

A call to `users.filter(army.canJoin, army)` can be replaced with `users.filter(user => army.canJoin(user))` are the same. Most people prefer the latter because itis easier to understand.

**Happy coding**

---


[![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1614817015187/dsl-EosQo.png)](https://www.buymeacoffee.com/techstackmedia)

---

<a href="https://skillshare.eqcm.net/c/2680282/974611/4650" target="_top" id="974611"><img src="//a.impactradius-go.com/display-ad/4650-974611" border="0" alt="" width="440" height="220"/></a><img height="0" width="0" src="https://skillshare.eqcm.net/i/2680282/974611/4650" style="position:absolute;visibility:hidden;" border="0" />













