0

I have an object like so:

Object {ABC-123: "XYZ", ABC-112: "LAX"}

and it is generated like so:

 var editObject = {};

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

I need to change my object so it looks like so:

[ { job: "ABC-123", task: "XYZ" }, { job: "ABC-333", task: "LAX" }]

how would I accomplish this?

1 Answer 1

1

Changing your editHolder iteration function to something like this should do it:

var editArray = [];

$.each(editHolder, function (index, value) {
    editArray.push({ job: value, task: $('#' + value).val() });
});

Or if you need to convert it after the fact, this should work:

var myArray = [];

for (var key in editObject ) {
    myArray.push( {job:key, editObject[key]} );
}
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.