Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
86
rated 0 times [  89] [ 3]  / answers: 1 / hits: 21788  / 11 Years ago, fri, october 11, 2013, 12:00:00

How to store the javascript variable into array?



I have these variable and I wish to store them into array:



var name=document.forms[form][name].value;
var email=document.forms[form][email].value;
var mobile=document.forms[form][mobile].value;
var q1=document.forms[form][q1].value;
var q2=document.forms[form][q2].value;
var q3=document.forms[form][q3].value;
var l1=document.forms[form][logo1].value;
var l2=document.forms[form][logo2].value;
var l3=document.forms[form][logo3].value;
var p1=document.forms[form][photo1].value;
var p2=document.forms[form][photo2].value;
var p3=document.forms[form][photo3].value;

More From » arrays

 Answers
109
var arr = [];
var name=document.forms[form][name].value;
var email=document.forms[form][email].value;
arr.push(name);
//etc


Using the .push() method



You could also serialize if you are going to post the form.


[#75070] Thursday, October 10, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
hallie

Total Points: 503
Total Questions: 114
Total Answers: 103

Location: Iraq
Member since Fri, Jun 5, 2020
4 Years ago
;