javascript - How do I remove an object inside a JSON object in Angular? -


my question goes this. have json object below. want remove object has assignment 1. looped through , best of me cannot seem remove particular object.

0: object   teller_id: 1   details: cash   assignments: array [2]    0: object  <---- remove object , elements indside       service_id: 1       status: 1       assignment: 1    1: object       service_id: 1       status: 1       assignment: 2 1: object  teller_id: 2  details: emp  assignments: array [2]    0: object       service_id: 2       status: 3       assignment: 4    1: object       service_id: 2       status: 4       assignment: 6 

remove object assignment of 1

0: object   teller_id: 1   details: cash   assignments: array [2]    1: object       service_id: 1       status: 1       assignment: 2 1: object  teller_id: 2  details: emp  assignments: array [2]    0: object       service_id: 2       status: 3       assignment: 4    1: object       service_id: 2       status: 4       assignment: 6 

in removes object[0] found inside assignments array. thanks

none of needs angular, because involves pure javascript.

in each object, assignments array. whilst array form of object, has own properties. there few ways approach this.

firstly if wish treat array, then:

myobject[0].assignments.splice(0,1); // remove first element array 

or:

myobject[0].assignments.shift(); // first element array 

this move indexes of assignments down in array. i.e. assignments[1] become assignments[0].

if don't want change indices, delete you're looking for:

delete myobject[0].assignments[0]; 

this cause first element of array have value undefined.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -