Dave's Brain

Browse - programming tips - javascript remove trailing empty array entries

Date: 2008mar14
Language: javaScript

Q.  How to I remove entries at the end of a javaScript array
    that are empty?

A.  Here is an efficient function that does it:

function removeTrailingEmpty(a) {
        while (a[a.length-1] == '') {
                a.pop();
        }
        return a;
}
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2012, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.
Advertisements: