Permalink
Browse files

Implemented Data.Collection#del

  • Loading branch information...
1 parent 79aee27 commit 0a65a8ab080043b6d98e931f4ff0b2d3cfc6ff07 Michael Aufreiter committed May 2, 2012
Showing with 12 additions and 3 deletions.
  1. +12 −3 data.js
View
15 data.js
@@ -514,6 +514,18 @@
}
return o;
},
+
+ // Delete object at given *key*
+ del: function (key) {
+ if (this.keys.hasOwnProperty(key)) {
+ var l = this.length;
+ var index = this.keys[key];
+ delete this.keys[key];
+ this.objects.splice(index, 1);
+ this.length = l-1;
+ }
+ return this;
+ },
// Find objects that match a particular query
find: function(qry) {
@@ -529,17 +541,14 @@
return this;
},
- // Returns the first item
first: function() {
return this.length > 0 ? this.objects[0] : null;
},
- // Returns the last item
last: function() {
return this.length > 0 ? this.objects[this.length-1] : null;
},
- // Returns a sub-range of the collection
range: function(start, end) {
var result = Data.Collection.create(this.type, []);
for(var i=start; i<=end && i<this.objects.length; i++) {

0 comments on commit 0a65a8a

Please sign in to comment.