title: console.log showing data but getting error in if condition javascript (using inside react component)
body: <p>I am new to Javascript, I am trying to invoke code on onClick event inside React container component below is my code</p>
  <pre><code>  const onClickHandler = (e) =&gt; {
      if (e != null){
        const row_id = e.target.getAttribute('key');
        var cur_row;
        if (api_data != undefined || api_data != null){
        for (cur_row=0; api_data.length-1; cur_row++){
          console.log('this is api data', api_data[cur_row]['id'])
          if (api_data[cur_row]['id'] == row_id){
            console.log(api_data[cur_row])
            break
          }
        }}
    }}
  </code></pre>
  <p>in above code api_data is hookstate variable in which i am storing data. in console log I am able to see the data but when it comes to if condition which is right below the console.log statement I am getting error 'Cannot read property 'id' of undefined'. I searched some similar questions but not able to understand who to fix my problem. Any idea what I am missing</p>