0

My code is supposed to accept a list of ID's, this list matches the scarlet-id on certain elements. My code then builds up an array with the elements attributes and the values. This is where the issues set in, when I console.log the array, it outputs in Chrome's console just fine.

Output to console

But when I pass the array to JSON.stringify, or try to use it in an AJAX request, none of the data gets transmitted. (below is the output from JSON.stringify)

JSON.stringify output

Here's my code.

function getScarletIDInfo(scarletIDs)
{

    var scarletIDinfo = new Array();    

    for (var i = 0; i < scarletIDs.length; i++) 
    {

        scarletIDinfo[scarletIDs[i]] = new Array();

        $($(getSpecificSelector(scarletIDs[i]))[0].attributes).each(function() 
        {

            scarletIDinfo[scarletIDs[i]][this.nodeName] = this.nodeValue;

        });

    };

    console.log(scarletIDinfo);
    console.log(JSON.stringify(scarletIDinfo));

    return scarletIDinfo;

}

function getSpecificSelector(scarletID)
{

    return "*[scarlet-id=" + scarletID + "]";

}

I'd be very grateful if somebody could point out where I'm going wrong.

1 Answer 1

4

You want an object, not an array.

var scarletIDingo = {};
// ...
    scarletIDinfo[scarletIDs[i]] = {};
// ...
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.