Search and assign CategoryApi object with categoryId
export class CategoryApi { categoryId: number; name: string; } categories: CategoryApi[]; selectedCategory: CategoryApi; selectedCategory = categories.findByIndex(2);
I found this javascript parameter, but Typescript complains about the function
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));
source share