I am in the process of trying to figure out how to increment the last element in an array using pop() and push(). I keep getting the original values after incrementing the pop array.
What needs to happen is that newArray needs to equal _array with the last element incremented by 1. For example '0,0,7' will change to '0,0,8'.
A slight shove in the right direction would be much appreciated.
var someArray = [0,0,7];
var incrementLastArrayElement = function(_array) {
var newArray = [];
var popArray = someArray.pop();
newArray = someArray.push(popArray++);
}
console.log(incrementLastArrayElement(someArray));
Aucun commentaire:
Enregistrer un commentaire