0

How can I concatenate a string to an element of an array and get its javascript value?

var values = ['asignatura_data.id', 'asignatura_data.nombre'];
var data = {id: 81, id_asignatura: "2", id_pensum: "7", semestre: "3", asignatura_data: {id:2, nombre:"REDES DE COMPUTO I"}};

function dibujarSelect(values = [], data = [], selector){
        var html = '';
        var id_select = values[0];
        var nombre_select = values[1];
        $(data).each(function (i, element) {
            console.log(element);
            html += '<option value="'+element+'.'+id_select+'">"'+element+'.'+nombre_select+'"</option>';
        });
        console.log(html);
 }
almcd
  • 1,069
  • 2
  • 16
  • 29
  • 1
    What do you mean by "get its javascript value"? You're already doing string concatenation in your code, so which value do you want to get from which object? – Capricorn Jul 12 '18 at 18:15
  • Are you talking about something like this with getting a value of dynamically created variable.. https://stackoverflow.com/q/10474306/3254405 Also you could assign a function to a variable where you do all this and it would be invoked when the variable is encountered.. https://stackoverflow.com/a/24018493/3254405 – boateng Jul 12 '18 at 19:23

0 Answers0