0

So I'm trying to extract an array with title attributes like so:

function pullContent() {
    var dir = './assets/slides/';
    var titles = [];

    $.ajax({
        url: dir,
        success: function (data) {

            $(data).find("li a").each(function () {

                var filename = $(this).attr('title');
                titles.push(filename);
            });
        }
    });
    return titles;
}

This is meant to pull the title attributes using ajax, push them into a array and then return the array.

The problem is that I don't know how to access said array because it returns without a name, like this: http://i64.tinypic.com/2hhhkq0.png

So my question is really just, how do I access an array like this?

I'm trying to catch it in another function and pull titles[0/1/2] but it doesn't work.

Nick09
  • 206
  • 2
  • 15
  • I've actually found this post at one point while searching but disregarded because at the time my code looked quite different and I didn't really understand much at 3 am back then. Looked over it again now and in the first 5 seconds I could tell that this is the solution and a good lessen to learn! Already fixed my problem :) How do I thank you? There's nothing to mark, nowhere to click to show my appreciation because this was awesome, thought me something about skipping over stuff to fast! Thank you – Nick09 Apr 12 '19 at 09:55
  • you can't show your appreciation for someone marking your question as a duplicate, I'm afraid. It's just an administrative step taken by the moderators to prevent the same content being repeated over and over again on the site. It's not the same as someone actually answering your question with a fresh answer. – ADyson Apr 12 '19 at 11:13
  • Oh ok, that seems fair then, thank you for your answer as well :) – Nick09 Apr 12 '19 at 11:39

0 Answers0