# elements

## Overview

The `elements` property is a top-level runtime feature in form scopes that provides access to all elements of a form. It allows for interaction with elements either by their names or by their indices. This property is versatile, offering methods to retrieve the names of all form elements as an array and to fetch elements individually.

## Features

The `elements` property offers access to elements through two main methods: indexed by name or by position. An array of all element names is accessible via the `allnames` property, and the total number of elements can be determined using the `length` property. These capabilities allow for dynamic interaction with form elements at runtime, enhancing flexibility in customizing and managing forms.

The property is universally supported across multiple clients, including Mobile, Web, Smart, and NG Client environments, making it a powerful tool in Servoy applications.

## Properties Summarized

| Type                                                                                             | Name                  | Summary                                                 |
| ------------------------------------------------------------------------------------------------ | --------------------- | ------------------------------------------------------- |
| [RuntimeComponent](/reference/servoycore/dev-api/forms/runtimeform/elements/runtimecomponent.md) | [\[index\]](#index)   | Get an element of the form by its index.                |
| [RuntimeComponent](/reference/servoycore/dev-api/forms/runtimeform/elements/runtimecomponent.md) | [\[name\]](#name)     | Get an element of the form by its name.                 |
| [Array](/reference/servoycore/dev-api/js-lib/array.md)                                           | [allnames](#allnames) | Get the names of all elements of the form, as an array. |
| [Number](/reference/servoycore/dev-api/js-lib/number.md)                                         | [length](#length)     | Get the number of elements of the form.                 |

## Properties Detailed

### \[index]

Get an element of the form by its index.

**Type**\
[RuntimeComponent](/reference/servoycore/dev-api/forms/runtimeform/elements/runtimecomponent.md)

**Sample**

```js
for (var i=0; i<elements.length; i++)
{
	var elem = elements[i];
	application.output(elem.getName() + ": " + elem.getDataProviderID());
}
```

### \[name]

Get an element of the form by its name.

**Type**\
[RuntimeComponent](/reference/servoycore/dev-api/forms/runtimeform/elements/runtimecomponent.md)

**Sample**

```js
for (var i=0; i<elements.allnames.length; i++)
{
	var name = elements.allnames[i];
	var elem = elements[name];
	application.output(name + ": " + elem.getDataProviderID());
}
```

### allnames

Get the names of all elements of the form, as an array.

**Type**\
[Array](/reference/servoycore/dev-api/js-lib/array.md)

**Sample**

```js
for (var i=0; i<elements.allnames.length; i++)
{
	var name = elements.allnames[i];
	var elem = elements[name];
	application.output(name + ": " + elem.getDataProviderID());
}
```

### length

Get the number of elements of the form.

**Type**\
[Number](/reference/servoycore/dev-api/js-lib/number.md)

**Sample**

```js
for (var i=0; i<elements.length; i++)
{
	var elem = elements[i];
	application.output(elem.getName() + ": " + elem.getDataProviderID());
}
```

***


---

# 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.servoy.com/reference/servoycore/dev-api/forms/runtimeform/elements.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.
