1

I have a angular array of 5 elements.

$scope.details; 

and $scope.details have these following elements [id, name, points].

and now using loop I have added a new element to this $scope.details for every element.

for(var i = 0; i < $scope.details.length; i++){ $scope.details[i].check = 'f'; } 

So, the elements are [id, name, points, check];

Now, after performing the logic i need to remove the check from all 5 elements of $scope.details.

3 Answers 3

2

Well, your code aren't adding check property to each element in details Array. To do it update code to:

for(var i=0; i<$scope.details.length; i++){ $scope.details[i].check = 'f'; } 

To remove check element from each item use for loop and delete:

for(var i=0; i<$scope.details.length, i++){ delete $scope.details[i].check } 

In your code snippet you adding check property to $scope.details, so you can remove it without for loop:

delete $scope.details.check 
Sign up to request clarification or add additional context in comments.

Comments

2

You can use delete like so:

for(var i=0;i<$scope.details.length;i++){ delete $scope.details[i].check; } 

Or using slightly newer API

$scope.details.forEach(function(item){ delete item.check; } 

1 Comment

I need to only delete the check from the array. So, that it would be again like [id, name,points]
0

We can pass index / id and write delete function in service js file as below:

RemoveFromCart(indexP){ this.items.splice(indexP, 1); } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.