Why this not working?
var inputs = new Array();
$("input").each(function(){
input = $(this).val();
})
console.log(input);
how to correctly use arrays in jQuery? Like as PHP?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I assume what you are trying to do is get an array of the values of all the
<input>elements on your page. What you’ll need to do is iterate over all the elements using the.each()function and append each value to yourinputsarray.Try this –
You need to use the
push()function to add an element to an array.fiddle demo
References –
As a final note, here is a shorthand way to define a new array –
That line is functionally identical to –