title: How to find index of a JSON array in Angular4?
body: <p>I have a JSON array:</p>
  
  <pre><code>data = [{"user_id":22},{"user_id":12}];
  </code></pre>
  
  <p>1) I need to find the index of an element. I use the method:</p>
  
  <pre><code>     var value = 22;
       var index = -1;
       var res = this.data.find(function(item, i){
        if(item.user_id === val){
        index = i;
        return i;
        }
       });
       console.log(index, res);
  </code></pre>
  
  <p>But the problem is that I got index <code>0</code> all the time.</p>
  
  <p>2) I need to use the same array in the format:</p>
  
  <pre><code>"test" :{
          "users":[{"user_id":22},
                   {"user_id":12}
                  ]
        }
  </code></pre>
  
  <p>when I use this format:</p>
  
  <pre><code>"test":{
          "users":this.data
          }
  </code></pre>
  
  <p>but it gives Array(0).</p>
  
  <p>I didn't find anything wrong. Help will be appreciated.</p>