Javascript includes() Array Method

How to use the javascript includes() array method.

How to use the javascript inclues array method.png

Below shows a typical use of the array method includes.

Additionally a template literal is used below with a placeholder ${userJohnExists} adding to the terseness of the code. Note that back-ticks (`) are used to denote a template literal.

const users = ["john", "derek", "tracey", "anna"];
let userJohnExists = users.includes("john");
console.log(`John exists: ${userJohnExists}`);

Output will be:

John exists: true

Author