Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

I have an angular scope array now i want to remove one item from that array using key name for example i want to remove DataTypeName from that array.

$scope.attributes = [
 {DataTypeName: "Text"
objectAttributeDataTypeId: "3654B05F-E09E-49A9-8E5F-0FC623BBE009"
objectAttributeId: "9df52354-67dd-453a-87fd-abb38b448db9"
objectAttributeLabelName: "test"
objectAttributeName: "test"}]

Please anyone help me to remove the array.

share|improve this question
    
you want to remove DataTypeName property from all the item in the array.. Is my understanding is right? – dhavalcengg Aug 13 at 10:57

2 Answers 2

up vote 1 down vote accepted

seems like you need to remove the objectAttributeDataTypeId from the first element of the array which is a object.

so what you need is,

$scope.attributes[0] // get the first element of the array
$scope.attributes[0].DataTypeName // get the DataTypeName attribute of the object
delete $scope.attributes[0].DataTypeName; // delete the property.

so all you need is,

delete $scope.attributes[0].DataTypeName;
share|improve this answer

If you want to filter array you can use native Array.prototype.filter method for this:

$scope = {}; // stub $scope for demo
$scope.attributes = [
  {
    DataTypeName: "Text",
    objectAttributeDataTypeId: "3654B05F-E09E-49A9-8E5F-0FC623BBE009",
    objectAttributeId: "9df52354-67dd-453a-87fd-abb38b448db9",
    objectAttributeLabelName: "test",
    objectAttributeName: "test"
  },
  {
    DataTypeName: "Image",
    objectAttributeDataTypeId: "3654B05F-E09E-49A9-8E5F-0FC623BBE009",
    objectAttributeId: "9df52354-67dd-453a-87fd-abb38b448db9",
    objectAttributeLabelName: "test",
    objectAttributeName: "test"
  }
];

// Filter out only "Text" types
$scope.filtered = $scope.attributes.filter(function(attr) {
    return attr.DataTypeName == "Text";
});

document.write('<pre>' + JSON.stringify($scope.filtered, null, 4));

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.