+ 8

How to create empty array in JavaScript and insert the values after

31st Mar 2019, 7:10 AM
Darcy Dev
Darcy Dev - avatar
4 Respuestas
+ 8
// You can do this by: var arr = [] ; arr.push("value1"); arr.push("value2"); //... console.log(arr); // value1, value2
31st Mar 2019, 7:54 AM
VEDANG
VEDANG - avatar
+ 2
You can create an empty array as var arrayName= []; and then to insert value in array you have many choices as 1. Using for loop for(var i= 0; i<noOfElements; i++){ arrayName.push("value"); } 2. Using this method as arrName[0]= value1; arrName[1]= value2; etc
31st Mar 2019, 2:23 PM
Prabhat Kumar Singh
Prabhat Kumar Singh - avatar
+ 1
var x = []; x[0] = 1; x[1] = 2; alert(x);
31st Mar 2019, 7:55 AM
Russ
Russ - avatar