I have a JSON array:
data = [{"user_id":22},{"user_id":12}];
1) I need to find the index of an element. I use the method:
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);
But the problem is that I got index 0 all the time.
2) I need to use the same array in the format:
"test" :{
"users":[{"user_id":22},
{"user_id":12}
]
}
when I use this format:
"test":{
"users":this.data
}
but it gives Array(0).
I didn't find anything wrong. Help will be appreciated.