So... I loaded json array trought Ajax, then I used $.each to put id values in an [] array.
Then I wanted to check if specific number that is in the variable exist in the array, so I tried using inArray and also indexOf in many different ways, tried changing to strings and integers, and nothing helped. I did waste few hours already at this...
Here's my Ajax code:
$.ajax({
method: "POST",
url: "loadost.php",
dataType: 'json',
data: {
"id" : id
},
success: function(ostloaded){
ostlength = ostloaded.length;
$.each($(ostloaded),function(key,value){
I added "loaded_id" to make sure it's integer, but it didn't help.
var loaded_id = parseInt(value.id);
idArray.push(loaded_id);
typ.push(value.typ);
link.push(value.link);
tyt_art.push(value.tytul_autor);
});
Here I sort where and when it should create elements
for(q = 0; q<=ostlength;q++){
if(typ[q] == 1){
$('<li class="op'+q+'"></li>').appendTo('body #ops');
$('<div/>').text(tyt_art[q]).appendTo('body .op'+q);
}
if(typ[q] == 2){
$('<li class="ed'+q+'"></li>').appendTo('body #eds');
$('<div/>').text(tyt_art[q]).appendTo('body .ed'+q);
}
if(typ[q] == 3){
$('<li class="ins'+q+'"></li>').appendTo('body #ins');
$('<div/>').text(tyt_art[q]).appendTo('body .ins'+q);
}
Then I create playlist
unflist.push(link[q]);
}
list = unflist.filter(function (el) {
return el != null;
});
loadsongs(0, list);
$(".playerHs").html(tyt_art[0]);
}
});
console.log($.inArray(pageId, idArray),idArray.indexOf(pageId), pageId, idArray);
the output no matter what - never changes, it's always like this: Console Log
I changed the names of the variables to make them clearer.