nriddock
asked on
javascript array - display obejcts
Hello,
I have the following code to search through an array for a specific ID.
It currently outputs only the ID and one object... "1 bar"
What do i need to do to output the values for ID, foo, my?
Thanks!
I have the following code to search through an array for a specific ID.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="jquery.js" type="text/javascript"></script>
<script type="text/javascript">
myArray = [{'id':'73','foo':'bar','my':'val'},{'id':'45','foo':'bar','my':'val'},{'id':'71','foo':'bar','my':'val'},{'id':'33','foo':'bar','my':'val'},{'id':'22','foo':'bar','my':'val'}];
var found = $.map(myArray, function(val) {
return val.id == '33' ? val.foo : null;
});
document.write(found.length + "\n" + found[0]);
</script>
</head>
</html>
It currently outputs only the ID and one object... "1 bar"
What do i need to do to output the values for ID, foo, my?
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
test page : http://jsfiddle.net/ujYuf/
ASKER