Querying Typescript Array Collection Based On Key
I am new to Typescript. I have an Array of type in typescript.Basically containing the collection elements as 'ID': '669a8156-528c-43ba-8ed0-d07874534d1c', 'Name': 'Temple', 'Dev
Solution 1:
You can use the JavaScript Array#filter
method for this, which returns an array of matches, very similar to your LINQ code:
array.filter(item => item.ID === ID)[0].name;
You could also use Array#find
, but that doesn't have very good browser support, so you might need a polyfill for Opera and Internet Explorer:
array.find(item => item.ID === ID).name;
Read documentation about it: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter
Post a Comment for "Querying Typescript Array Collection Based On Key"