title: How to get matches string element from array in angular or javascript
body: <p>I have 3 divs and click event, I am using a variable and calling a function in each event.
  Now I have an array <code>this.newarray = [&quot;one&quot;, &quot;two&quot;, &quot;three&quot;];</code> I want to match the elements from the array with variable. If its success need to show <code>alert</code>. I have commented statically but I need it from array element. Here is the code below  <a href="https://stackblitz.com/edit/angular-jk3xsa?file=src%2Fapp%2Fapp.component.ts" rel="nofollow noreferrer">https://stackblitz.com/edit/angular-jk3xsa?file=src%2Fapp%2Fapp.component.ts</a></p>
  <h2>app.component.html</h2>
  <pre><code>&lt;hello name=&quot;{{ name }}&quot;&gt;&lt;/hello&gt;
  &lt;p&gt;
      Start editing to see some magic happen :)
  &lt;/p&gt;
  &lt;div (click)=&quot;click1()&quot;&gt;Click1&lt;/div&gt;
  &lt;div (click)=&quot;click2()&quot;&gt;Click2&lt;/div&gt;
  &lt;div (click)=&quot;click3()&quot;&gt;Click3&lt;/div&gt;
  </code></pre>
  <h2>app.component.ts</h2>
  <pre><code>import { Component, onInit } from &quot;@angular/core&quot;;
  
  @Component({
    selector: &quot;my-app&quot;,
    templateUrl: &quot;./app.component.html&quot;,
    styleUrls: [&quot;./app.component.css&quot;]
  })
  export class AppComponent {
    name = &quot;Angular&quot;;
    newarray: any;
    matchoutput: any;
  
    ngOninit() {
      this.matchoutput = &quot;one&quot;;
      this.newarray = [&quot;one&quot;, &quot;two&quot;, &quot;three&quot;];
    }
    function1() {
      if (this.matchoutput == this.newarray.indexOf(this.matchoutput)) {
        alert(&quot;hello&quot;);
      }
      /*if (this.matchoutput == &quot;one&quot; || this.matchoutput == &quot;two&quot;) {
        alert(&quot;hello&quot;);
      }*/
    }
    click1() {
      this.matchoutput = &quot;one&quot;;
      this.function1();
    }
    click2() {
      this.matchoutput = &quot;two&quot;;
      this.function1();
    }
    click3() {
      this.matchoutput = &quot;three&quot;;
      this.function1();
    }
  }
  </code></pre>