I am trying to rewrite a .php multi-dimentional array and foreach loop (the one used in the "Sponsor Flip Wall" jQuery example found at http://tutorialzine.com/2010/03/sponsor-wall-flip-jquery-css/) in JSON/JavaScript, as unfortunately the Web host I am being forced to use does not have PHP support.
The array originally looked as follows:
$sponsors = array(
array('facebook','The biggest social network in the world.','http://www.facebook.com/'),
array('adobe','The leading software developer targeted at web designers and developers.','http://www.adobe.com/'),
array('microsoft','One of the top software companies of the world.','http://www.microsoft.com/')
);
and I now have the following:
var sponsors = [
{ "name": "facebook", "description": "The biggest social network in the world.", "website": "http://www.facebook.com/" },
{ "name": "adobe", "description": "The leading software developer targeted at web designers and developers.", "website": "http://www.adobe.com/" },
{ "name": "microsoft", "description": "One of the top software companies of the world.", "website": "http://www.microsoft.com/" },
];
However I am stumped at the foreach loop, as I don't believe JavaScript has a direct comparison? Upon research, it seems I will either need to use the jQuery $.each or for loops within for loops.
I was looking at the answer to How do I iterate over a JSON structure? but is seems that their array only contains two values - an object and a key. Mine has multiple fields per object so I don't think it completely applies? Or if it does, I don't know how to expand upon it?
The .php foreach loop I am trying to recreate:
foreach($sponsors as $company)
{
echo $company[0] . ":" . $company[1] . "(" . $company[2] . ")"; //eg.
}
Any ideas? (I would prefer my answer was written purely in JavaScript as opposed to jQuery, if possible)