Variable in Object Arrangement

0

first of all a greeting. My detail is the following one I obtain by means of ajax data that I put in some variables that are the following ones

        var cveProd = info.Resultado.cveProducto;
        var descVal = info.Resultado.DesValor;
        var hola  = [{idclave: CveProd , descc: descVal }];

Hello I want to put them as an arrangement of objects BUT I receive this

[{"idclave": [" AL-32021611 "," AL-32021612 ", " AL-32021612 ", " AL-32021612 "],
"descc":["7500","Continental","Piso R3","7500"]}]

and it's complicated for me because I need something like this and I can not think of how to do it

var hola= [
{
    idclave: "AL-32021612",
    descc: "7500"    },

{
    idclave: "AL-32021612",
    descc: "Continental"    },

{
    idclave: "AL-32021612",
    descc: "Piso R3"    },

{
    idclave: "AL-32021612"
    descc: "7500",
         }];

Thanks for reading.

    
asked by Godeolo 24.02.2017 в 00:08
source

1 answer

0

With the following solution, if the arrangements have a different length, there will be elements left outside. In addition, it is assumed that the arrangements come in the correct order, which depends on your backend.

With those caveats, you can try this:

    var cveProd = [" AL-32021611 "," AL-32021612 ", " AL-32021612 ", " AL-32021612 "];
    var descVal = ["7500","Continental","Piso R3","7500"];
    var hola  = [];
    var largo_arreglos=Math.min(cveProd.length, descVal.length);
    
    for(var i=0;i<largo_arreglos;i++) {
      hola.push({idclave: cveProd[i], descc: descVal[i] });
    }
    console.log(hola);
    
answered by 24.02.2017 / 00:14
source