Documentation v1.0.13

Array Helper

Helper Description
findObjectInArray Finds an object in an array based on the specified field name and value.

findObjectInArray

Finds an object in an array based on the specified field name and value.
Parameters:
  • array: Array<{[key: string]: any}>
    The array of objects to search.
  • fieldName: string
    The name of the field to search.
  • fieldValue: any
    The value to search for.
Return:
  • object|null The first object in the array that matches the criteria, or null if no match is found.
// results in: "Item A"
const items = [{id: 123, name: 'Item A'}, {id: 456, name: 'Item B'}];
hbs.compile(
`{{#each items}}
  {{#if (eq id 123)}}
    {{lookup (findObjectInArray ../items 'id' id) 'name'}}
  {{/if}}
{{/each}}`)({items});