I have this code:
var deptDictionary={
<?php foreach($dept as $cd){
echo '"'.$cd->department_id.'":"'.$cd->department_name.'",';
}
?>
};
which outputed this:
'Object {1: "ACCOUNTING", 5: "HUMAN RESOURCES", 6: "DEVELOPERS", 15: "ENGINEERING", 23: "ASDASD", 26: "QWEQWE"} '
now, I want to find the index of ACCOUNTING
by just inputting the data it points to.
[what's that part called anyway if index is the first part of assoc array?]
I have tried this:
console.log(deptDictionary["accounting"]);
but it returned undefined
. Am I missing something? Is there any reading material that points to js assoc array?
EDIT: OK. I have reversed the key and the data, to fit my needs. now it looks like this:
var deptDictionary={
<?php foreach($dept as $cd){
echo '"'.$cd->department_name.'":"'.$cd->department_id.'",';
}
?>
};
But I am still raising this question for future reference, if some other guy finds it important to find the key.