Category: Question and Answers
Updated

This solution is summarized from an archived support forum post. This information may have changed. If you notice an error, please let us know in Discord.

Get a variable from inside an array and pass it through pages

Issue

I am having trouble fetching and displaying just one or two variables from an array returned by an API call on page 1. Additionally, I need to pass these variables to page 2 after checking the password entered by the user.

Resolution

The user has two pages, page 1 and page 2. In page 1, the user inputs a password which is used to fetch a single record from Airtable. The record is returned as an array with several properties. The user needs to display or store just one or two variables from that array.

To do this, the user can use the array index to access the specific variable they need. For example, if the array is called "record" and the user needs the first property, they can do:

const firstProperty = record[0];

To pass the variables to page 2, the user can use a query parameter in the URL. For example, if the variable is called "name" and has a value of "John", the URL would be:

https://example.com/page2?name=John

In page 2, the user can access the query parameter with JavaScript using the URLSearchParams method. For example:

const params = new URLSearchParams(window.location.search);
const name = params.get("name");

This will retrieve the value of the "name" parameter in the URL.

Overall, the user needs to use array indexing to access specific variables in the returned array and pass them to page 2 using query parameters in the URL. In page 2, the user can access the parameters using JavaScript.