How to write input object array with for...loop in JavaScript? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to write input object array with for...loop in JavaScript?

26th Nov 2017, 9:58 AM
Luke
Luke - avatar
3 Answers
+ 3
var obj = { first: 'Hurong', last: 'Acoustic' }; var objArray =[]; objArray.push(obj);
26th Nov 2017, 10:46 AM
Calviղ
Calviղ - avatar
+ 3
Javascript cannot access HTML code directly. You can use document.querySelectorAll('form input[type="text"')[i].value to accees each input values. Remember input tags always come together in form tag. You need a submit button at the end of all these input to submit the inputs to Javascript. eg <input type="submit" onclick='submit(event)'> in Javascript, add submit function: function submit(e) { e.preventDefault(); // add the get inputs code here } and please note that i iterator must be initialized to zero: eg. for(i=0;i<3;i++)
27th Nov 2017, 12:28 AM
Calviղ
Calviղ - avatar
+ 1
var arr=[]; for (i;i<3;i++){ arr.push(<input type='text'/>)}; why does my code is wrong?
26th Nov 2017, 4:18 PM
Luke
Luke - avatar