2

I have object: $scope.formData = {}

How I can delete element in object by $index:

 $scope.formData.university[$index];

I tried:

$scope.formData.university.splice($index);
0

2 Answers 2

1

You can use 'delete' operator. For more info Refer Link

 delete  $scope.formData.university[$index];
Sign up to request clarification or add additional context in comments.

Comments

1

It should have slice first parameter as $index & then second one would be 1

$scope.formData.university.splice($index, 1);

Note: using $index for deleting element would be risky if you are applying filtering on ng-repeat

Instead of that you could add some unique prop in your each element of ng-repeat you could add id in it, so that while deleting you could pass that id and then do find index of that element and delete that element from an array like the same way I did wrote above code.

3 Comments

TypeError: $scope.formData.university.splice is not a function
@Ahmed does $scope.formData.university has values?
Yes, has value: Object {0: "nnnnnn", 1: "jkjbbubiuiu"}

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.