I’ve got this function that defines a random color set.
My issue is defining the variable (var target) to select the new color set from the kuler object.
kuler: {
set0:['#499E8D','#85CC9F','#A4DEAB','#C8E8C7','#FFF6C9'],
set1:['#0F2440','#2C3F59','#518C8C','#94BEAC','#D9CAAD'],
set2:['#499E8D','#85CC9F','#A4DEAB','#C8E8C7','#FFF6C9'],
set3:['#0F2440','#2C3F59','#518C8C','#94BEAC','#D9CAAD'],
set4:['#499E8D','#85CC9F','#A4DEAB','#C8E8C7','#FFF6C9'],
set5:['#0F2440','#2C3F59','#518C8C','#94BEAC','#D9CAAD'],
set6:['#499E8D','#85CC9F','#A4DEAB','#C8E8C7','#FFF6C9']
},
setNewColourSet: function () {
rn=Math.floor(Math.random()*5);
for (i=0; i<4; i++){
var target = "project.kuler.set"+rn+"["+i+"]";
$('.kuler'+i).css('background-color',target);
/* works */// $('.kuler'+i).css('background-color',project.kuler.set4[i]);
}
}
In think you were close — just put the string within the square braces.
var target = project.kuler['set' + rn][i];assuming
rnis the number appended to'set', andkuleris itself in an object literal calledproject.Note the first brace (
kuler['set'+rn]) is property access on the object literalkuler, and the second brace ([i])is array index access on an array….