TypeScript simplest way to check if item exists in array like C# Linq Any ( using any library ). Something like
var myArray=[1,2,3,4]; var is_3_Exist=myArray.Any(x=> x==3);
The includes() method determines whether an array contains a specified element. This method returns true if the array contains the element, and false if not.
You can use the includes() method in JavaScript to check if an item exists in an array. You can also use it to check if a substring exists within a string. It returns true if the item is found in the array/string and false if the item doesn't exist.
Using includes() Method: If array contains an object/element can be determined by using includes() method. This method returns true if the array contains the object/element else return false. Example: html.
To check if given Array contains a specified element in C programming, iterate over the elements of array, and during each iteration check if this element is equal to the element we are searching for.
Use .some
:
myArray.some(x=>x==3);
FIDDLE: https://jsfiddle.net/vktawbzg/
NPM: https://www.npmjs.com/package/linqscript
GITHUB: https://github.com/sevensc/linqscript
Take a look at my Github Repository. It would be great if you guys can help to improve it! https://github.com/sevensc/linqscript
Syntax:
list.Any(c => c.Name === ("Apple"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With