Go through an object and take out a selected variable and in another, the others it contains

0

I am trying to go through an object that contains information, and if I remove one of the elements, I do not know how I have to do to remove the others that I have not selected. This is the code:

var finalActTabs = {
        fTab1: '#a1, #a2, #a3',
        fTab2: '#b1, #b2, #b3',
        fTab3: '#c1, #c2, #c3'
    };

    for (var k in finalActTabs){
        var selected = finalActTabs[k];
    }

This way I have selected the one I want according to the order, but how do I put in another variable, the data that contains the object that has not been called in each journey? Thank you very much in advance.

    
asked by djohny 20.02.2017 в 10:54
source

2 answers

0

Correct, I think I've already understood what you need.

var finalActTabs = {
    fTab1: '#a1, #a2, #a3',
    fTab2: '#b1, #b2, #b3',
    fTab3: '#c1, #c2, #c3'        
};

var j = 0;

for (var k in finalActTabs) {
    if (j === 1) {
        break;
    }
    var selected = finalActTabs[k];
    console.log('seleccionado: ' + finalActTabs[k]);

    // no seleccionados
    var noSeleccionados = finalActTabs; // aqui tienes todos, quitamos el seleccionado y tendrás un array con los elementos no seleccionados
    delete noSeleccionados[k]; // eliminamos la seleccionada
    console.log(noSeleccionados);

    j++;
}
    
answered by 20.02.2017 / 11:00
source
0

To f_bartstar:

var finalActTabs = {
            fTab1: '#a1, #a2, #a3',
            fTab2: '#b1, #b2, #b3',
            fTab3: '#c1, #c2, #c3'        
        };

        var j = 0;

        for (var k in finalActTabs) {
            if (j === 1) {
                break;
            }
            var selected = finalActTabs[k];
            console.log('seleccionado: ' + finalActTabs[k]);
            j++;
        }

        // -- inicio código añadido --

        var noSeleccionados = []; // indices no seleccionados

        for (var k in finalActTabs) { // recorremos de nuevo
            if (finalActTabs[k] != selected) { // si no es el seleccionado
                noSeleccionados.push(finalActTabs[k]); // añadimos al array de no seleccionados
            }
        }
        // recorremos el nuevo array
        for (i = 0; i < 1; i++) {
            console.log('no seleccionado: ' + noSeleccionados[i]);
        }

This is what happens in one pass. I think I will extend myself so that it is better understood.

I'm going to create a new instance for each view we go through the finalActTabs object, so in a variable the selected element will go and in another, the sum of the rest of the elements, even if it's an array I apply a join or something like that and ready. The fact is that I can not select or filter the others.

    
answered by 20.02.2017 в 11:40