So I have an object that looks like this:
Object
maddiekeller: Object
rickbross: Object
firstname:"Rick"
lastname:"Bross"
firstname:"1234 Fictional Drive"
...
__proto__: Object
and I can pull any of the first names out by saying:
alert(potentialmodels.rickbross.firstname);
//Alerts "Rick"
Now how can I store all of the first names from all the models in an array? Am I able to loop through them when they all have different firstnames?
potentialmodels.*differentfirstname*.firstname
Here is how I am generating the object:
$result = mysql_query("SELECT * FROM `potentials`") or die(mysql_error());
$rows = array();
//retrieve and print every record
while($r = mysql_fetch_assoc($result)){
$rows[strtolower($r['firstname'].$r['lastname'])] = $r;
}
$myJSON = json_encode($rows);
and my JavaScript:
var potentialModels = <?php print($myJSON); ?>;
console.log(potentialModels);
console.log(potentialModels.rickbross.firstname);