Search for values from one array in another and return a specific position

1

I have these two arrays, the first one is made up of foreign keys that come from the BD and the second one by the detail of one of those foreign keys. How can I go through the 0 position of my first array and search the second for the value of that position and return the determinant:

(6) ["1", "1", "si", "1", "37", "238,835,836"]
    0:"1"
    1:"1"
    2:"si"
    3:"1"
    4:"37"
    5:"238,835,836"
    length:6

(4) [{…}, {…}, {…}, {…}]
    0:{0: "1", 1: "DATO 1", idDeterminante: "1", detDeterminante: "DATO 1"}
    1:{0: "2", 1: "DATO 2", idDeterminante: "2", detDeterminante: "DATO 2"}
    2:{0: "3", 1: "DATO 3", idDeterminante: "3", detDeterminante: "DATO 3"}
    3:{0: "4", 1: "DATO 4", idDeterminante: "4", detDeterminante: "DATO 4"}
    length:4

Ex:

In my first array I have the value 1 in position 0. I want to look for that value in the different positions of array two and when I find it return the determinant that corresponds to it.

    
asked by Juan 18.09.2018 в 00:36
source

2 answers

1

You can search by comparing the index 0 of the first array with the property Determinant of the second. Something like this:

var lista1= ["1", "1", "si", "1", "37", "238,835,836"];
var lista2= [
    {0: "1", 1: "DATO 1", idDeterminante: "1", detDeterminante: "DATO 1"},
    {0: "2", 1: "DATO 2", idDeterminante: "2", detDeterminante: "DATO 2"},
    {0: "3", 1: "DATO 3", idDeterminante: "3", detDeterminante: "DATO 3"},
    {0: "4", 1: "DATO 4", idDeterminante: "4", detDeterminante: "DATO 4"}
];

function buscar_en(posicion){
    var obtenido= lista2.filter( function( item){  
        return item.idDeterminante == posicion;
    })[0];
    console.log(  obtenido.detDeterminante);
}

buscar_en(lista1[0]);
    
answered by 18.09.2018 / 01:19
source
0
var lista1= ["1", "1", "si", "1", "37", "238,835,836"];
var lista2= [
    {0: "1", 1: "DATO 1", idDeterminante: "1", detDeterminante: "DATO 1"},
    {0: "2", 1: "DATO 2", idDeterminante: "2", detDeterminante: "DATO 2"},
    {0: "3", 1: "DATO 3", idDeterminante: "3", detDeterminante: "DATO 3"},
    {0: "4", 1: "DATO 4", idDeterminante: "4", detDeterminante: "DATO 4"}
];

function buscar_en(posicion){
    var obtenido= lista2.filter( function( item){  
        return item.idDeterminante == lista1[ posicion]; //  posicion 0
    })[0];
    console.log(  obtenido.detDeterminante);
}

buscar_en(0);
    
answered by 18.09.2018 в 00:59