I decided to extend the array features of JsonDB by adding a new semantic rule:
The use of -1 to get the last element
In the previous revision I added the support for Appending, I thought why not add a simple way to get the last item in an array without having to fetch the array first then get the length and finally the right index.
All this is now done for you by using the -1
Example
// Add basic array db.push("/arraytest/lastItemArray", [1, 2, 3], true); //You can easily get the last item of the array with the index -1 //This will return 3 db.get("/arraytest/lastItemArray[-1]"); //You can delete the last item of an array with -1 //This will remove the integer "3" from the array db.delete("/arraytest/lastItemArray[-1]"); //This will return 2 since 3 just got removed db.get("/arraytest/lastItemArray[-1]");
Leave a Reply