JavaScript: Add object inside an array of objects

0

I have:

var options = {
    title: 'Titulo',
    width: largura,
    height: altura,
    vAxis: {
        title:"Porcentagem % em vendas",
        format: 'decimal'
    },
    hAxis: {
        title: "Seleção de clientes - Comutativa",
    }
}

However after some time, in order to generate a new view, I need to pass the following value to the options variable:

vAxis:{
    ticks:[0,10,20,30,40,50,60,70,80,90,100]
}

But I do not know the correct operator to give a push in options , as I often do not know what's inside options then I need to add (+ =) inside the object vAxis

    
asked by anonymous 09.10.2018 / 20:37

1 answer

0

Is this what you are looking for?

var largura = 15;
var altura = 25;
var options = {
    title: 'Titulo',
    width: largura,
    height: altura,
    vAxis: {
        title:"Porcentagem % em vendas",
        format: 'decimal'
    },
    hAxis: {
        title: "Seleção de clientes - Comutativa",
    }
}

console.log(options);

var nOptions = Object.assign({}, options, {
        vAxis: Object.assign({}, options.vAxis, { 
            ticks: [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
        }) 
    });

console.log(nOptions);
    
11.10.2018 / 01:14