This code, which I've found somewhere online, works fine and it's kind of what I'm trying to accomplish:
$(document).ready(function(){
var arrData = [ "j", "Q", "u", "e","r","y" ];
alert(jQuery.inArray("Q", arrData));
});
However, I have an array from a loop with php/mysql that I output and save like this:
$query = mysql_query("SELECT * FROM geo_orter");
while(($row = mysql_fetch_assoc($query))){
$i = $row['ort_id'];
$result[$i] = $row['ortnamn'];
};
$allaOrterjson=json_encode($result);
Then I go ahead and do this, which works:
var allaOrter=<?php echo $allaOrterjson ?>;
document.write(allaOrter[0] + allaOrter[1] + allaOrter[2]);
and gives me
undefinedAborremålaAbbjörnahall
Here's the issue:
I tried
$(document).ready(function(){
alert(jQuery.inArray("Aborremåla", allaOrter));
});
but it results in "-1" (Not found).
I'm trying to find out the index nr of an item in the array. Any ideas?
Log result: