ES6 version of this is (check out answer from Allison):

!str1.includes(str2)

The original accepted answer was:

You are looking for indexOf

var x = "home.subjects.subject.exams.exam.tests";
console.log(x.indexOf('subjects'));     // Prints 5
console.log(x.indexOf('state'));        // Prints -1
Answer from Ananth on Stack Overflow
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Why "not includes" doesn't work? - JavaScript - The freeCodeCamp Forum
December 16, 2019 - Tell us what’s happening: I’m trying to solve this using a for loop so I can iterate through the args and solve the problem of having more than 3 args in. Using .includes on my if statement is returning the elements in the arr found in the other args, however, when I negate that, I’m ...
🌐
Sololearn
sololearn.com › en › Discuss › 3009586 › how-to-make-a-not-includes-in-js
How to make a NOT includes in js | Sololearn: Learn to code for FREE!
Let's say you checked it as follows ... var exists = haystack.includes( needle ); <exists> will be true when <haystack> has <needle> as one of its substring. If you want to inverse <exists> in JS log, you can simply use the unary logical NOT operator as follows, console.log ( !exists );
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-array-not-includes
Check if Array Doesn't contain a Value in JavaScript | bobbyhadz
The falsy values in JavaScript are: null, undefined, empty string, NaN, 0 and false. If you have to perform the test often, define a reusable function. ... Copied!function notIncludes(array, value) { return !array.includes(value); } const arr = ['a', 'b', 'c']; console.log(notIncludes(arr, 'c')); // 👉️ false console.log(notIncludes(arr, 'd')); // 👉️ true console.log(notIncludes(arr, 'z')); // 👉️ true
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › includes
String.prototype.includes() - JavaScript | MDN
const sentence = "The quick brown fox jumps over the lazy dog."; const word = "fox"; console.log( `The word "${word}" ${ sentence.includes(word) ? "is" : "is not" } in the sentence`, ); // Expected output: "The word "fox" is in the sentence"
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › includes
Array.prototype.includes() - JavaScript | MDN
[1, 2, 3].includes(2); // true [1, 2, 3].includes(4); // false [1, 2, 3].includes(3, 3); // false [1, 2, 3].includes(3, -1); // true [1, 2, NaN].includes(NaN); // true ["1", "2", "3"].includes(3); // false · If fromIndex is greater than or equal to the length of the array, false is returned. The array will not be searched.
🌐
Reddit
reddit.com › r/webdev › javascript .includes not working / issues
r/webdev on Reddit: Javascript .includes not working / issues
August 2, 2018 -

Hi All,

Trying to get a little function going where when a client leaves a * or symbol in a certain table cell, the background color of that table cell will change.

This is all in a `if is_page())` and I'm also using ACF.

I receive this error in Chrome Console:

Uncaught TypeError: cells.includes is not a function

Any assistance would be great!

UPDATE: SOLUTION IS BELOW

Solution:

<script type="text/javascript">
function cellColorBlue() {
var tableCells = [...document.querySelectorAll("td")];
for (cell of tableCells) {
	if(cell.innerText.includes("*")) {
	cell.style.backgroundColor = "#63b2df";
	} 
} 
}

function cellColorGreen() {
var tableCells = [...document.querySelectorAll("td")];
for (cell of tableCells) {
	if(cell.innerText.includes("^")) {
	cell.style.backgroundColor = "#9ce158";
	} 
} 
}

cellColorBlue();
cellColorGreen();
</script>
🌐
sebhastian
sebhastian.com › javascript-array-not-includes
JavaScript Array Not Includes a Certain Value | sebhastian
October 26, 2023 - This is useful when you need to ... array doesn’t contain a certain value, you need to use the logical NOT ! operator and negate the call to the includes() method....
Find elsewhere
Top answer
1 of 2
3

Because Array in js is a specific object, the [2,4] inside myArray is object and [2,4] that you switch to includes is anther object. If you want that includes return true you must do this:

var array = [2, 4]

const myArray = [array, "cat", "hamster", 9]

console.log(myArray.includes(array))
2 of 2
3

A string is a value type, so a comparison between two strings will compare the value of those strings. In your case the value cat. However, an array is an object with reference comparison, not value comparison. So when comparing two arrays the reference will be compared. That is if you compare the same object to itself the result will be true. However, as is the case in your example, if you compare two different objects even with all the properties set to the same value, the result will be false.

let a = [1,2];
let b = 2;
let c = "string";
let d = [1,2];

a === a; //true reference comparison comparing an object to itself
b === 2; //true value comparison
c === "string"; //true again value comparison, even though it's two different objects
a === d; //false the values are the same but it's reference  comparison

Array.includes iterates through the array and makes a comparison between the argument and the individual elements using the above comparison types depending on the types.

It's also important to note that includes uses strict comparison. That is if a comparison with === results in true then so would includes. It's not enough that == would result in true. "2" == 2is an example of a comparison that returns true where ["2"].includes(2) returns false

🌐
Mimo
mimo.org › glossary › javascript › includes-method
JavaScript includes() method: Syntax, Usage, and Examples
Doesn't Work for Objects: For arrays of objects, includes() will not find a match unless you have the exact same object reference. Use some() for these cases instead. ... Become a full-stack developer. Learn HTML, CSS, JavaScript, and React as well as NodeJS, Express, and SQL
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Includes vs. In - JavaScript - The freeCodeCamp Forum
August 18, 2022 - Today I ran into some trouble with a line of code that seems to be misleading. I tried to use if (!(arr[n][i] in arr[0])){ but I found I had to rewrite the code as if (!(result.includes(arr[n][i]))){ I am having dif…
🌐
PTC Community
community.ptc.com › t5 › ThingWorx-Developers › Using-includes-on-a-string-never-works › td-p › 628132
Solved: Using .includes() on a string never works - PTC Community
September 24, 2019 - The .includes() function is not available. ... Yes, ThingWorx uses a custom version of Rhino for JavaScript processing in Services that conforms (with some exceptions) to the ECMAScript 5 specification.The ECMAScript 5 Specification can be found here.
🌐
Reddit
reddit.com › r/javahelp › what is the opposite of .contains (does not contain)
r/javahelp on Reddit: What is the opposite of .contains (does not contain)
February 25, 2021 -

I have a line of code :

If (apple.getValue(true).contains(pear)) { assertNotEquals(pear, apple.getValue(true))

Question: How do I do the same line of code but have "not contains" instead of "contains"?

🌐
SheCodes
shecodes.io › athena › 220596-how-to-use-the-includes-method-in-javascript
[JavaScript] - How to use the .includes() method in | SheCodes
Learn how to use the `.includes()` method in JavaScript to check if a specific string or element is present in another string or array.
🌐
Sentry
sentry.io › sentry answers › javascript › how do i check if an array includes a value in javascript?
How do I check if an array includes a value in JavaScript? | Sentry
There are two JavaScript array methods that are commonly used to find a value in an array: includes() and indexOf(). If you are checking if an array contains a primitive value, such as a string or number, the solution is more straightforward than if you are checking for a value that’s an object. A primitive value is a value that’s not an object.