To check whether an array contains a specific element in TypeScript, we can use the .includes()
method. Here's an example:
index.ts197 chars8 lines
In this example, we create an array of strings and use the .includes()
method to check if it includes the string 'banana'. If it does, we log a message accordingly.
Note that the .includes()
method returns a boolean value, which makes it ideal for conditional statements.
gistlibby LogSnag