includes() Method in Javascript
In Javascript, There is includes()
powerful method which is separately used in array and string expressions.
includes() Method at string expressions:
Usage: str.includes(searchvalue, start)
includes() method returns true if string expression has specified value. includes() method is case sensitive.
let text = "My name is etem, this website awesome."; let result = text.includes("etem"); console.log(result); // Output: true result = text.includes("Etem"); console.log(result); // Output: false
includes() Method at array expressions:
includes() method returns true if array has specified value.
const array1 = [1, 2, 3]; let result = array1.includes(2); console.log(result); // Output: true result = array1.includes(5); console.log(result); // Output: false array1.includes(3, -1) console.log(result); // Output: true
When using at array expressions, includes() method can take negative value as second parameter.
Good luck…