title: Uncaught TypeError: Cannot read property 'indexOf' of undefined in javascript
body: <pre><code>var id    = $('.getval_'+product_id+''+index+'').attr("id");
  var value = "";
  
  console.log(id);
  //data that return by id
  6059
  s2id_6061
  6122
  s2id_8410
  
  if (id.indexOf('s2id_') &gt; 0) {
      value = $('.getval_'+product_id+''+index+'').select2('val');
  }else{      
      value = $('.getval_'+product_id+''+index+'').val();
  }
  </code></pre>
  
  <p><strong>Question:</strong>
  The code above is show that when the <strong>ID</strong> return by jquery, then it will show a list of data, so what I want is when the <strong>ID</strong> return, if the in front of <strong>ID</strong> don't have <strong>s2id_</strong> it will go else statement. But the code return an error which is <strong>(Uncaught TypeError: Cannot read property 'indexOf' of undefined)</strong></p>