Link to home
Start Free TrialLog in
Avatar of nriddock
nriddockFlag for United States of America

asked on

javascript array - display obejcts

Hello,

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>

Open in new window


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
Avatar of Ahmed Hussein
Ahmed Hussein
Flag of Egypt image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nriddock

ASKER

Beautiful! That worked perfectly. Thanks!
Avatar of leakim971