0

I have an array like so ['ABC123', 'ABC124'] and I am trying to put these items into an object so I can add more items:

var editObject = {};

        $.each(editHolder, function () {
            editObject[editHolder] = $('#' + editHolder).text();
        });

        console.log(editObject);

but this returns Object {ABC123,ABC124: ""}

what I am expecting is {ABC123: "text", ABC124: "text2"}

$('#' + editHolder).text(); is suppose to be the text in an input text feild with that id (which does exist)

1 Answer 1

1

You need to provide variables to your function and use them instead of full object:

var editObject = {};

$.each(editHolder, function (index, value) {
    editObject[value] = $('#' + value).text();
});

console.log(editObject);

Here you can read more information about jQuery.each function

Sign up to request clarification or add additional context in comments.

Comments

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.