I am trying to create a function that uses the push() or pop() methods as arguments when it is called. I have a working a code but I noticed that I repeated myself a lot and I know that a function would help to improve my code quality, however, I have not been able to find a way to dynamically introduce the push() or pop() methods so I do not have to repeat the same lines of code when I want to do something similar.
This is the current working code (and this is similar to other lines):
pushBtn.addEventListener("click", () => {
if (inputEl.value) {
myEmojis.push(inputEl.value)
inputEl.value = ""
}
render(myEmojis)
})
I created a function that I would pass the push() argument to but it doesn't work as expected. Here is the function I tried to create:
function modifyEmoji(action) {
if (inputEl.value) {
myEmojis.action(inputEl.value)
inputEl.value = ""
}
render(myEmojis)
}
How I call the function:
pushBtn.addEventListener("click", () => {
modifyEmoji(push)
})
This returns: "Uncaught TypeError: myEmojis.action is not a function"
Thanks in advance.