Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Dear Stackoverflow friends,

I have a question, i'm busy with a NodeJS - Angular application. To save and delete parts of a form i use an object:

$scope.entries = {
  events:{
    save:{},
    del:[],
    save_count:0},

  actions:{
    save:{},
    del:[],
    save_count:0},

  packages:{
    save:{},
    del:[],
    save_count:0}
}

Now for example i have an object like this (saved in packages)

save:{
  1398944325398:{
   action: 6461,
   budget: 1000,
   events: [123, 1242],
   id: 209
   name: "Jeffrey"},
 1398949842824:{
   action: 6441,
   budget: 1020,
   events: [153, 12422],
   id: 21
   name: "Jeffrey2"}
}

So when i want to delete the key: 1398944325398 I have the following code:

delete $scope.entries.package.save['1398944325398'];

But when i send this object $scope.entries to my Node server i get this:

packages:{
 del: Array[0],
 save:{
  1398944325398:{
   events: Array[0]
  },
  1398949842824:{
   action: 6441,
   budget: 1020,
   events: [153, 12422],
   id: 21
   name: "Jeffrey2"}
 },
 save_count: 0
}

Why won't javascript delete my object if there is an array in that object? Setting the array to 'null' Won't solve the problem

share|improve this question
1  
jsfiddle.net/eBbkP This is your scenario right? Seems to do whats expected in the browser –  Marco de Jongh May 1 at 11:56
    
why you put the code with syntax errors or this is the real example? –  Andrey Borisko May 1 at 11:59
    
Like @AndreyBorisko asked, is this a real example? You're trying to delete from "package" but the property is called "packages"? –  Reinard Mavronicolas May 1 at 12:15
    
This is the real problem, if i change the property from a object to a string like so: $scope.entries.package.save['1398944325398'] = "test"; I'll get an Angular error: docs.angularjs.org/error/$rootScope/… Seems like i have a problem with my $watch –  Jeffrey Bouva May 1 at 12:20
1  
@JeffreyBouva are you calling it $scope.entries.packages or $scope.entries.package? (the missing 's' at the end). this makes a big difference –  japrescott May 1 at 13:17
show 2 more comments

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.