Looking to get into development? As a full-stack developer I guide you on this journey and give you bite sized tips every single day 👊
I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
Markdown supported · ⌘↵ to post
.includes() method is definitely my favorite way of checking if array contains a value, it makes code that much more readable.
indexOf() is the "old way" of doing it because includes() is only supported in IE Edge 14+ (no IE11 support).
But when targeting modern browsers, or a transpiler or node.js - includes() is the way to go.
Fun fact - you can also use it on strings to check if string includes a value too:
"Does foobar".includes("foo")
// true
I love these kind of posts 👊! A good follow up would be an Array with Objects 😉
Mahesh
Nice Article buddy. Crisp. I too write almost in the same way. Please have a look at my article on all array methods: