I received an interesting issue about JsonDB not deleting correctly the index in an Array:
[github-issue username=”belphemur” repository=”node-json-db” number=”10″]
I thought using the delete keyword on an index in an array was deleting it (rendering its value undefined). In fact, it only set the index value to NULL.
Don’t do
var test = {array:[1,2,3]}; delete test.array[1]; console.log(test.array); //[1, Ā , 3]
Do
var test = {array:[1,2,3]}; test.array.splice(1,1); //Remove from index 1, 1 item. console.log(test.array); //[1, 3]
Conclusion
If you want to remove also the index from the array, use the splice. If you want to keep your index table intact, but remove only the value, use delete.
Leave a Reply