Best way to pass several variables

-1

Very good, I have a form in which to accept, I have to pass the content of 5 fields to a function, my question is: Is there any way a little more efficient to pass 5 variables to a function? Maybe Json? Thank you very much

    
asked by Lorenzo Martín 04.09.2017 в 14:47
source

1 answer

1

When you have many variables it is more comfortable that you create an object and pass it as a parameter directly.

Here is a simple example:

var obj = {
            valor1 : 1,
            valor2 : 2,
            valor3 : 3,
            valor4 : 4,
            valor5 : 5
           }
            
function Ejemplo(objeto) {
  console.log(objeto.valor2);
}

Ejemplo(obj);
    
answered by 04.09.2017 / 15:05
source