---
source: https://carbone.io/documentation/design/substitutions/array-search.html
title: "Search an item within an array without doing a loop"
description: "Search an item within an array without doing a loop"
generated_at: "2026-07-13"
---

# Array search

Search an item within an array without doing a loop  
COMMUNITY FEATURE Available for:  
✓ Carbone Cloud  
✓ Carbone On-premise  
✓ Embedded Carbone JS   v2.0+ 

## Simple filters

Instead of using the **reserved word `i`** to [access the i-th item](/documentation/design/substitutions/the-basics.md#accessing-arrays) of an array, Carbone accepts filters using attributes of objects.

If the filter returns many rows, Carbone keeps only the first occurrence.

Use single quotes to filter text that contains spaces.

```cdata
[
  { "name": "Inception", "year": 2010 },
  { "name": "Matrix", "year": 1999 },
  { "name": "Back to the future", "year": 1985 }
]
```

```ctemplate
The movie of 1999 was {d[year=1999].name}
Back to the future: {d[name='Back to the future'].year}
```

```cresult
The movie of 1999 was Matrix
Back to the future: 1985
```

## Variable filter

UPDATED v4.2.0+

If the second operand starts with a period, Carbone considers that the operand is a variable coming from the JSON

```cdata
  {
    "parent" : {
      "qty" : 2
    },
    "subArray" : [{
      "text" : 1000,
      "other" : 1,
      "sub" : {
        "b" : { "c" : 1 }
      }
    },{
      "text" : 2000,
      "other" : 1,
      "sub" : {
        "b" : { "c" : 2 }
      }
    }]
  }
```

```ctemplate
{d.subArray[sub.b.c = .other].text}
{d.subArray[sub.b.c = ..parent.qty].text}
```

```cresult
1000
2000
```

## Multiple array filters

Multiple filters are accepted, even using a sub-object.

If the filter returns many rows, Carbone keeps only the first occurrence.

```cdata
[
  { "name": "Interstellar"  , "year": 2014, "meta": { "type": "SF"    } },
  { "name": "Matrix"        , "year": 1999, "meta": { "type": "SF"    } },
  { "name": "The Green Mile", "year": 1999, "meta": { "type": "Drama" } }
]
```

```ctemplate
{d[year=1999, meta.type='SF'].name}
```

```cresult
Matrix
```

## Last element

Get the last element of a list with a negative index `[i=-1]`. If you want to get the second to last, you have to use `[i=-2]`. Here is an example:

This filter can be used also in a [repetition loop](/documentation/design/repetitions/filtering.md#exclude-the-last-n-items).

```cdata
[
  { "name": "Inception", "year": 2010 },
  { "name": "Matrix", "year": 1999 },
  { "name": "BTTF", "year": 1985 }
]
```

```ctemplate
The oldest movie was {d[i=-1].name}.
```

```cresult
The oldest movie was BTTF.
```

## Filter and print parent

Access properties of the parent object with two points `..` (or more) when you need to print a parent property using filters in nested arrays:

```cdata
{
  "country": "USA",
  "movies": [
    { "name": "Inception", "year": 2010 },
    { "name": "Matrix", "year": 1999 },
    { "name": "BTTF", "year": 1985 }
  ]
}
```

```ctemplate
{d.movies[year=1999]..country}
```

```cresult
USA
```

## Related topics

- [The basics](/documentation/design/substitutions/the-basics.md)
- [Aliases](/documentation/design/substitutions/aliases.md)
