# journey.viewStack

{% hint style="info" %}
**Version compatibility**

`journey.viewStack` was introduced in version **4.40.1** of the JourneyApps Container.
{% endhint %}

The view stack is exposed to developers as `journey.viewStack`.

Example usage:

```javascript
var views = journey.viewStack.views() // returns an array of view instances

var myView = journey.viewStack.findFirst('my_view_path'); // view instance or null

var myView = journey.viewStack.findLast('my_view_path'); // view instance or null
var myView = journey.viewStack.find('my_view_path'); // view instance or null
```

A view instance contains the following items:

| Name      | Type   | Comment                                        |
| --------- | ------ | ---------------------------------------------- |
| path      | string | The path name of the view, e.g. "inventory".   |
| index     | number | The position of the view on the stack, e.g. 3. |
| variables | object | Read-only object of the view variables.        |

`journey.viewStack.findFirst()` finds the first instance of the view on the stack, i.e. the one closest to the 'main' view.

`journey.viewStack.findLast()` finds the last instance of the view on the stack, i.e. the one closest to the current view. Since finding the last view on the stack is the more common, you can also use the alias `journey.viewStack.find()`.


---

# 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://docs.journeyapps.com/reference/build/js-ts-apis/journey/viewstack.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.
