title: How to get the index of the clicked array element using JavaScript?
body: <p>I have a array list of span elements dynamically created. I want to get the index of the clicked span element.</p>
  
  <pre><code>boundItemClick(e) {
      console.log(e.target) //results &lt;span&gt;some label&lt;/span&gt;
  }
  render() {
      var data=[];
      data.push (&lt;div&gt;
          &lt;span&gt;{textLabel} onClick={this.boundItemClick.bind(this)}&lt;/span&gt;
          &lt;/div&gt;
  }
  </code></pre>
  
  <p>However I'm unable to get the index this way, what is the best way to get the index of a clicked array element?</p>
  
  <p><a href="https://i.stack.imgur.com/ib60l.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ib60l.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/K5JW6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/K5JW6.png" alt="enter image description here"></a></p>