That could be part of the solution. The problem is the logic, arr[i]!==elem
. arr[i] is an array so it will never be equal to the number in elem. What you need to know is if arr includes elem. Is there an array method that will return a true or false if the array includes an item? Lasjorg mentioned it.
And when in doubt, check the docs. I go to MDN all the time to confirm little things:
Have a look at the array prototype methods along the left side.
I need to learn more about methods js.
Yeah, they can be confusing at first - I remember. But they are also really powerful. I mean, there is nothing you can do with a method that you can’t do with a loop, but it is a lot cleaner and “safer” with the method.
You just have to use them. There are youtube videos that talk about each of them - check some out. When you really, really want to learn them, try writing your own versions.