I would like to figure out how to concatenate an object in a for loop; eval() works fine, but I would like optimum efficiency and much of what I have searched on Google leads me to believe eval() is not a safe choice. I have looked at other examples that relate to eval(), however, none seem to be the same case.
I'm a beginner with Javascript, so apologies if this has an easy resolution.
objFunction: function () {
var concat1;
var concat2;
$('table tbody tr').each(function (i) {
i++;
for (var x = 1; x <= 4; x++) {
concat1 = 'obj1.obj2.obj3.step' + i + '[' + x + ']' + '.name';
concat2 = 'obj1.obj2.obj3.step' + i + '[' + x + ']' + '.icon';
console.log(eval(concat1));
console.log(eval(concat2));
});
}
Thanks,