a {
text-decoration: underline;
cursor: pointer;
}
JavaScript
var col_settext1 = new Array();
col_settext1['field_id1'] = '#FF0000';
col_settext1['field_id2'] = '#00FFFF';
var txt_settext1 = new Array();
txt_settext1['field_id3'] = 'Some Text Here';
txt_settext1['field_id4'] = 'Another Text Here';
var txt_settext2 = new Array();
txt_settext2['field_id5'] = 'Some Text Here';
var col_settext2 = new Array();
col_settext2['field_id6'] = 'Another Text Here';
var chk_settext2 = new Array();
chk_settext2['field_id7'] = "checked";
$('.button').click(function () {
$myclass = this.id;
var col = 'col_' + $myclass;
var txt = 'txt_' + $myclass;
var chk = 'chk_' + $myclass;
alert('variavel col = ' + col);
alert('variavel txt = ' + txt);
alert('variavel chk = ' + chk);
var newarray = $.extend(true, {}, col_settext1);
alert('valor contido no array: '+newarray['field_id1']);
// Preciso copiar o valor do array utilizando
// uma variavel, no caso a 'col' que tem o valor
// do mesmo nome do array que preciso copiar
var variablearray = $.extend(true, {}, col); // <-- col precisa retornar #FF0000 (mesmo da função acima)
// Aqui não ta retornando nada...
// preciso que retorne o valor contido
// no array mas utilizando o nome do
// array de forma dinamica utilizando a variavel
alert('valor do array com variavel: '+variablearray['field_id1']);
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.