If I have an array from the calculator input like this [9, 8, 7, 6, 5, "+", "-", 9, 8]
How to find the character in an array and take only the last character that the user clicks? In this array it will take only "-"
and the array will be [9, 8, 7, 6, 5, "-", 9, 8]
I think I can use pop()
to take the last character.
My code:
["plus", "minus", "devide", "multiply"].map(op => {
let selector = "#" + op;
$(selector).on("click", function(e) {
result.push(e.currentTarget.innerText);
// console.log(result);
// $("#input").html(operator);
// let newValue = result.concat(operator);
if (operator.length >= 1) {
let newOperator = operator.pop();
console.log("newOperator" + newOperator);
// result.push(newOperator);
// return operator;
$("#input").html(result);
}
$("#input").html(result);
});
});