I have the following code. I am not sure why the myData array is empty in console.log as inputValue and inputName are not null and I can see them in log
var myData = new Array();
$("#myelement :input").each(function(){
var inputValue = $(this).val();
var inputName = $(this).attr('id');
console.log(inputValue, inputName);
myData.push=inputName;
myData.push=inputValue;
console.log(myData);
});
This isn’t right:
Basically, you are setting the
pushproperty of the array to a value. But thepushproperty of an array is already set to something, the function that adds an item to the array.You want to call the
pushmethod instead, not replace it: