# wire.Collection

A collection is a basic programming structure that allows an array of objects to be maintained using a field as a unique key.

The following creates a new `Collection` object from `users` using the `UserName` field as the key.  The first parameter to the constructor is the key field and the second is the array of objects.

```javascript
let users = [
    { UserName: "apeters", FullName: "Amy Peters" },
    { UserName: "pdougherty", FullName: "Pat Dougherty" },
    { UserName: "tleach", FullName: "Tim Leach" }
];

let collection = new wire.Collection("UserName", users);
```

Use the following methods to maintain a collection of users.

## Methods

| Name                     | Description                                                                                                                                                                                          |
| ------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| array                    | Returns the array of objects inside the collection.                                                                                                                                                  |
| clear                    | Clears the collections array.                                                                                                                                                                        |
| get(value)               | Returns the object with the key value `value`.                                                                                                                                                       |
| index(value)             | Returns the 0 index position of the object with the key value `value`.                                                                                                                               |
| length                   | Returns the length of the internal array.                                                                                                                                                            |
| move(fromIndex, toIndex) | Moves on object inside the collection from 0 index position `fromIndex` to `toIndex`.                                                                                                                |
| remove(key)              | Removes the object with the key value `value`.                                                                                                                                                       |
| set(object)              | Adds the object to the collection. If the object already exists with the existing key field value, it replaces the current one in the collection.  If not, it is added to the collection at the end. |

For more examples on using WireBootstrap collections, visit [Collections](/wirebootstrap/utilities/collections.md).


---

# 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.wirebootstrap.com/wirebootstrap/reference/wire/wire.collection.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.
