Typescript Array find element by index
<p>Finding and assigning a CategoryApi object having categoryId</p>

<pre><code>export class CategoryApi {
    categoryId: number;
    name: string;
}

categories: CategoryApi[];
selectedCategory: CategoryApi;

selectedCategory = categories.findByIndex(2); //looking for categoryApi by categoryId = 2
</code></pre>

<p>I found this javascript option but Typescript is complaining about function</p>

<pre><code>var inventory = [
    {name: 'apples', quantity: 2},
    {name: 'bananas', quantity: 0},
    {name: 'cherries', quantity: 5}
];

function findCherries(fruit) { 
    return fruit.name === 'cherries';
}

console.log(inventory.find(findCherries)); // { name: 'cherries', quantity: 5 }
</code></pre>