# Collections

WireBootstrap collections allow an array of objects to be managed using one of the attributes as a key.

## Create a Collection&#x20;

To create a collection, create a new instance of the `wire.Collection` class passing in the key field that makes each row unique along with the array of data.

```javascript
let users = [
    { UserName: "jkratz", FullName: "Jamie Kratz", Active: true },
    { UserName: "pdougherty", FullName: "Pat Dougherty" Active: true },
    { UserName: "mchermela", FullName: "Mike Chermela", Active: false }
];

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

## Add an Object

To add an object, use the `set` method on the collection.  This method will add the object to the collection if it does not already exist.  If the object exists, it will be overwritten with the object that is passed into the method.

```javascript
...

const amy = { UserName: "apeters", FullName: "Amy Peters", Active: true };
    
const mike = col.set(amy);
```

## Retrieve an Object

To pull an object out of the collection, use the `get` method with the key value.

```javascript
...

const mike = col.get("mchermela");
```

## Remove an Object

Use the `remove` method with the key to remove an object from the collection.

```javascript
...

col.remove("jkratz");
```

## Retrieve the Array

To pull the array out of the collection, use the array method.

```javascript
...

const users = col.array();
```

For more on WireBootstrap collections, visit [wire.Collection](/wirebootstrap/reference/wire/wire.collection.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/utilities/collections.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.
