How can I enter data with the push to an array?

0

How can I enter data with the push to an array with a while? because I want to graph with canvas and the only thing I need is to put the values to the arrangement with the push to print them, here is my code.

var meses = [""];
var valores = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
var consulta = "SELECT * FROM produccion WHERE area AND fecha BETWEEN #"+fecha+"# AND #"+fechaFinal+"#";
tablaRecord.Open(consulta, cadConexion);
while(!tablaRecord.eof){    
    meses.push();

    tablaRecord.MoveNext();
}
    
asked by Micha Ruiz 19.04.2018 в 00:58
source

2 answers

0

I do not understand why traverse an array to put its elements in another, when you can do it directly using concat .

  

The concat() method is used to join two or more arrays . This method does not   changes the existing arrays, but returns a new array.

     

MDN documentation

Let's see:

var meses = ['enero']; 
var consulta = ['febrero', 'abril', 'diciembre']; 

/*Creamos un nuevo array combinado*/
var newArr =meses.concat(consulta);

/*Prueba*/
console.log(newArr);
    
answered by 19.04.2018 в 01:37
0

You must include the data to be added as push arguments.

Example

var meses = []; // Array a llenar
var consulta = ['enero','febrero']; // datos a pasar al array
while(consulta[0]){
  meses.push(consulta[0]); // Agregar primer elemento de la consulta al array a llenar
  consulta.shift(); // Eliminar el primer elemento del array consulta
}
console.info(meses); // Mostrar resultado en la consola

If you do not want to use shift you can use an iterator

var meses = []; // Array a llenar
var consulta = ['enero','febrero']; // datos a pasar al array
var i = 0;
while(consulta[i]){
  meses.push(consulta[i]); // Agregar primer elemento de la consulta al array a llenar
  i++; // Incrementamos el iterador
}
console.info(meses); // Mostrar resultado en la consola

NOTE: The use of using shift or an iterator is really irrelevant since you are asking for push.

    
answered by 19.04.2018 в 01:23