# Fighters Game Example

Let's say we have an array of objects representing the different fighters in the game, with each object containing properties like the fighter's name, attack power, and health points. Here's an example of such an array:

```javascript
const fighters = [
  { name: "Ryu", attack: 80, hp: 100 },
  { name: "Chun-Li", attack: 90, hp: 120 },
  { name: "Guile", attack: 70, hp: 110 },
  { name: "Zangief", attack: 100, hp: 130 }
];
```

Now, let's say we want to create a new array that contains the names of all the fighters with more than 100 health points. We can use the `map()` method to do this by calling `map()` on the `fighters` array and passing a function that extracts the `name` property from each object and returns it. Here's how we could do this:

```javascript
const toughFighters = fighters.map(fighter => fighter.name);

console.log(toughFighters); // Output: ["Ryu", "Chun-Li", "Guile", "Zangief"]
```

The `toughFighters` array now contains the names of all the fighters in the `fighters` array. If we wanted to filter the array to only include fighters with more than 100 health points, we could use the `filter()` method in combination with `map()` like this:

```javascript
const toughFighters = fighters
  .filter(fighter => fighter.hp > 100)
  .map(fighter => fighter.name);

console.log(toughFighters); // Output: ["Chun-Li", "Zangief"]
```

In this example, `filter()` is used to create a new array that only includes fighters with more than 100 health points, and then `map()` is used to create a new array that contains the names of those fighters.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://demirels-organization.gitbook.io/javascript-tutorial/transforming-array-of-objects/fighters-game-example.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
