1

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);
        });
0

1 Answer 1

9

This isn't right:

myData.push=inputName;
myData.push=inputValue

Basically, you are setting the push property of the array to a value. But the push property of an array is already set to something, the function that adds an item to the array.

You want to call the push method instead, not replace it:

myData.push(inputName);
myData.push(inputValue);
Sign up to request clarification or add additional context in comments.

1 Comment

Been a long day :) didn't even realize I was doing that :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.