0

im taking first steps in angular, and i need to return array excluding empty spaces in it. i was able to create function to return the array i want, spliced, but couldn't find a way to make sure each cell in the array contains a value. this is my function:

$scope.letters = function(arr) {
    var lettersarray = arr.split('');
    return lettersarray;
};

is there a way to do it in angular?

  • i know a way in jquery but understood its not recommended to mix both so im looking for an "angularish" way to do it..thx

1 Answer 1

1

There's no real "Angular" way to do it, why not just use native JS and .map

function trimArraySpaces(arr) {
    return arr.map(function(item) {
        return item.trim();
    });
}

var testArr = ["John    ", "Sally    "],
    trimmedArr = trimArraySpaces(testArr); //["John", "Sally"]
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.