Last active
October 19, 2018 21:00
-
-
Save dewey92/97f3c93e4c81af9511e978571227dff2 to your computer and use it in GitHub Desktop.
Array find
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface ProductModel { | |
| id: number; | |
| name: string; | |
| price: number; | |
| tax: number | |
| } | |
| const productList: ProductModel[] = [ | |
| { id: 100, name: 'deluxe', price: 28, tax: 2.5 }, | |
| { id: 101, name: 'giftcard', price: 30, tax: 3 }, | |
| { id: 102, name: 'vase', price: 4.5, tax: 1.25 }, | |
| ... | |
| ]; | |
| const getProductById = (products: ProductModel[], id: number) => | |
| products.find(product => product.id === id); | |
| const product = getProductById(productList, 1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment