A simple for loop should be able to do this:
for (x in i_array){
iv[ii_array[x]] = i_array[x];
v[iii_array[x]] = i_array[x];
}
See jsfiddle here.
UPDATED TO SOLVE REAL PROBLEM
Your code was messed up in a few places. See working jsfiddle here.
First of all, you don’t need to create new arrays. Just use the index of your circleCol or squareCol arrays to pull the color values from the availableColors array.
Like this:
$.each(squareCol, function(index, className) {
cValue = avaibleColors[index];
var canvasClass="."+className;
...
Second, you don’t need to check if your canvasClass variable is null, because $.each() will pull each value of the array and no more; therefore, it will always pull a value for canvasClass, which in your case is the array key.
If anything you should use if (canvas.getContext){
as described in the MDN canvas tutorial.
Hope this helps. I kind of entirely redid the script, so I can’t say exactly where the problem was. I know that it was difficult to get the combined arrays to work with the $.each() functions.
The problem was:
$.each() didn’t work on the combined arrays. It did, however, work, if you used a for…in… loop. See JSFIDDLE.
Notice that you get nothing in console or in an alert if you tried to get the values from squareObj or circleObj. I think it’s because it turned into an object. But I’m not familiar with this, so I can’t say for sure.
8
solved Jquery array from arrays