RayT
asked on
Javascript Arrays & Loops
I Array A:
var Colors = new Array();
Colors[0]="Red";
Colors[1]="Green";
Colors[2]="Blue";
and Array B
var Hues = new Array();
Hues[0]=["Red"];
Hues[1]=["Green"];
Hues[2]=["Blue"];
How do I programmatically loop through Colors(A) to create the array Hues(B)?
var Colors = new Array();
Colors[0]="Red";
Colors[1]="Green";
Colors[2]="Blue";
and Array B
var Hues = new Array();
Hues[0]=["Red"];
Hues[1]=["Green"];
Hues[2]=["Blue"];
How do I programmatically loop through Colors(A) to create the array Hues(B)?
ASKER
Not quite
I have an array that looks like this
var Cars= new Array();
Cars[0]="Gallery/Car/Honda .png";
Cars[1]="Gallery/Car/Ford. jpg";
Cars[2]="Gallery/Car/SAAB. jpg";
The function I am using has a parameter that needs an array passed to it that looks like this:
[["Gallery/Car/Honda.png"] , ["Gallery/Car/Ford.jpg"], ["Gallery/Car/SAAB.jpg"]]
How do I build this value programmatically?
I have an array that looks like this
var Cars= new Array();
Cars[0]="Gallery/Car/Honda
Cars[1]="Gallery/Car/Ford.
Cars[2]="Gallery/Car/SAAB.
The function I am using has a parameter that needs an array passed to it that looks like this:
[["Gallery/Car/Honda.png"]
How do I build this value programmatically?
So, in my example above if I changed it to be a function that accepted the colors array as a parameter it'd work? Could you post the function you are trying to use?
What you originally asked for might look like this:
<script type="text/javascript">
var Colors = ["Red",'Green","Blue"];
var Hues = new Array();
for (x in Colors)
{
var myColor = Colors[x];
Hues[x] = [myColor]; // an array with one element
}
</script>
Oops, there's a single quote that should be a double in line 2
Sorry.
var Colors = ["Red","Green","Blue"];
Sorry.
ASKER
Here's a simple explanation of what I'm trying to do. I need to convert a single dimension array to a multi-dimension array. Here what I have but it doesn't work. It only displays the 1st image. How do I make it work?
var Cars= new Array();
Cars[0] = "Gallery/Car/Acura.jpg";
Cars[1] = "Gallery/Car/Honda.jpg";
var o = new Array(Cars,Cars);
jQuery.slimbox(o, 0, { loop: true });
var Cars= new Array();
Cars[0] = "Gallery/Car/Acura.jpg";
Cars[1] = "Gallery/Car/Honda.jpg";
var o = new Array(Cars,Cars);
jQuery.slimbox(o, 0, { loop: true });
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Here's the output
Gallery/Car/Acura.jpg Gallery/Car/Honda.jpg
Gallery/Car/Acura.jpg Gallery/Car/Honda.jpg
For the 1st column I was expecting to see
Gallery/Car/Acura.jpg
Gallery/Car/Honda.jpg
Is that possible?
Gallery/Car/Acura.jpg Gallery/Car/Honda.jpg
Gallery/Car/Acura.jpg Gallery/Car/Honda.jpg
For the 1st column I was expecting to see
Gallery/Car/Acura.jpg
Gallery/Car/Honda.jpg
Is that possible?
ASKER
How do I create a multi-demensional array?
The result should be something like this:
Gallery/Car/Acura.jpg 'Blue'
Gallery/Car/Honda.jpg 'Red'
The result should be something like this:
Gallery/Car/Acura.jpg 'Blue'
Gallery/Car/Honda.jpg 'Red'
ASKER
So to create the array I would use
var x = new Array(new Array(1,2,3),new Array('A','B','C'));
How do I populate it?
var x = new Array(new Array(1,2,3),new Array('A','B','C'));
How do I populate it?
ASKER
Okay. Here's what I need. How can I programmatically build an array to look like this
var Cars= new Array();
Cars[0] = "Gallery/Car/Acura.jpg";
Cars[1] = "Gallery/Car/Honda.jpg";
Cars[2] = "Gallery/Car/Mazda.jpg";
I need to loop thru Cars to build the following
var o = new Array(new Array("Gallery/Car/Acura.j pg"), new Array('Gallery/Car/Honda.j pg'), new Array('Gallery/Car/Mazda.j pg'));
var Cars= new Array();
Cars[0] = "Gallery/Car/Acura.jpg";
Cars[1] = "Gallery/Car/Honda.jpg";
Cars[2] = "Gallery/Car/Mazda.jpg";
I need to loop thru Cars to build the following
var o = new Array(new Array("Gallery/Car/Acura.j
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks!!!!
<script type="text/javascript">
var Colors = new Array();
Colors[0]="Red";
Colors[1]="Green";
Colors[2]="Blue";
var Hues = new Array();
for (x in Colors)
{
Hues[x] = Colors[x];
}
</script>