# Search Table Data

## Content

The `search` method retrieves records that exactly match a specified value in a given field.
Search characteristics:

* Case-sensitive.
* Exact match only.
* Returns all matching records.
* Returns an empty array if no match is found.
* Returns an empty array if the field does not exist.
* Uses an index if available.
* Falls back to linear scanning if no index exists.

## Using search()

```javascript
table.search(value, field);
```

### Parameters

* `value` \- The value to search\. Non\-string values are internally converted to string\.
* `field` \- The target field name\.

## Return Value

Returns an array of matching record objects.
Example result:

```javascript
[
  { Month: "Jan", Sales: 120 }
]
```

If no record matches:

```javascript
[]
```

## Example with Index

```javascript
var dataManager = spread.dataManager();

var supplierTable = dataManager.addTable("Supplier", {
  remote: {
    read: { url: apiUrl }
  }
});

supplierTable.fetch().then(function () {
  supplierTable.createIndexes(["CompanyName", "City"]);

  var result =
    supplierTable.search("New Carlisle", "City");

  console.log(result);
});
```

### Assumed Data

Assume the table contains the following records:

```javascript
[
  { SupplierID: 1, CompanyName: "Tokyo Traders", City: "Tokyo" },
  { SupplierID: 2, CompanyName: "Grand Foods", City: "New Carlisle" },
  { SupplierID: 3, CompanyName: "Sunrise Market", City: "New Carlisle" }
]
```

### Search Result

```javascript
[
  { SupplierID: 2, CompanyName: "Grand Foods", City: "New Carlisle" },
  { SupplierID: 3, CompanyName: "Sunrise Market", City: "New Carlisle" }
]
```

If `"City"` is indexed, the lookup uses the index.
If `"City"` is not indexed, the table performs a linear scan and returns the same result, but with lower performance on large datasets.