0

I am getting the list titles from my sharepoint site, I have made an app that gets "longest title name" so far, now I want to be able to get the "shortest title name" aswell, so this was my code to get the longest:

function onSuccess() {

    var listString;
    var listEnumerator = listCollection.getEnumerator();

    var longest = "";

    while (listEnumerator.moveNext()) {
        var currentItem = listEnumerator.get_current(),
            title = currentItem.get_title();

        listString += "<br>" + title;

        if (longest.length < title.length)
            longest = title;
    }
    $('#divAllaListor').html(longest);
}

Now how do I do the same thing but getting the "shortest list title" instead of "the longest one"? :)

0

The following should work:

function onSuccess() {

    var listString;
    var listEnumerator = listCollection.getEnumerator();

    var shortest = "";

    while (listEnumerator.moveNext()) {
        var currentItem = listEnumerator.get_current(),
            title = currentItem.get_title();

       if (shortest == "") { shortest = title; }

        listString += "<br>" + title;

        if (shortest.length > title.length)
            shortest = title;
    }
    $('#divAllaListor').html(shortest);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.