88willr
88willr

Reputation: 148

create nested array from ajax result

$.ajax({
type: "GET",
dataType: 'jsonp',
url: 'https://wiljcr.blogspot.com/feeds/posts/default/5158425934439969382?alt=json-in-script',
success: function(data) {
    var entry = data.entry;
    $(entry).each(function() {
        content = this.content.$t;
        myArray = {};
        $.each($(content), function() {
            var getClass = $(this).attr('class');
            myArray[getClass] = $(this).find("li").map(function() {
                return $(this).text();
            }).get()
        });
        console.log(myArray);
    });
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Current output, after countless trial n error:

{
    am: ["gud am", "good morning"],
    greetings: ["hi", "hello", "hey"]
}

Desired output:

[
    am = ["gud am", "good morning"],
    greetings = ["hi", "hello", "hey"]
]

Thanks for your help...

Upvotes: 0

Views: 46

Answers (1)

mplungjan
mplungjan

Reputation: 177702

The closest you can get would be

myArray=[];
myArray.push($(this).find("li").map(function() {$(this).text()}).get());

Upvotes: 1

Related Questions