0

here is my code in jsfiddle

var app = angular.module("app", []);

app.controller("MyCtrl1", MyCtrl1);

function MyCtrl1($scope) {

    $scope.block = new Array();

    $scope.block[0] = new Array();
    $scope.block[0].push("111");
    $scope.block[0].push("112");
    $scope.block[0].push("113");
    $scope.block[0].push("114");
    $scope.block[0].push("115");

    $scope.block[2].length = 0;

    $scope.block[3] = new Array();
    $scope.block[3].push("111");
    $scope.block[3].push("112");
    $scope.block[3].push("113");
    $scope.block[3].push("114");
    $scope.block[3].push("115");


    $scope.block.filter(Boolean);

    console.log($scope.block.length.toString());

}

[["111","112","113","114","115"],["111","112","113","114","115"],[],["111","112","113","114","115"]]

how to remove the empty array Thanks help~

2 Answers 2

3

Array#filter does not modify the array it's called on. It returns a new array.

Also, Boolean([]) is true so that won't work here.

Do this:

$scope.block = $scope.block.filter(function (arr) {
    return arr.length;
});

http://jsfiddle.net/wmLmrqrq/

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your swift response to solve my problem, thank you
1

If I understand your question correctly, this should do the trick:

$scope.block.splice(2,1)

The first parameter specifies the index of the "block" array. The second parameter specifies how many items to remove starting at that index.

2 Comments

@user3382559 This will only work if you know in advance where the item to remove is (and won't remove multiple items at once).
@JLRishe Good ~ Thank you for reminding me, I will pay attention to these

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.