I may be incorrect, but I don't think the Array 'includes()' method is available in ServiceNow JS engine at this time. It's an ECMAScript 2016 method: · Array.prototype.includes() - JavaScript | MDN · filter() and map() are available if that helps. You could also try using the 'ArrayUtil' library, it has a similar method called 'contains()': · https://developer.servicenow.com/app.do#!/api_doc?v=jakarta&id=c_ArrayUtilAPI · Cheers, · Tim Answer from Community Alums on servicenow.com
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › filter
Array.prototype.filter() - JavaScript | MDN
December 13, 2025 - The filter() method is an iterative method. It calls a provided callbackFn function once for each element in an array, and constructs a new array of all the values for which callbackFn returns a truthy value. Array elements which do not pass the callbackFn test are not included in the new array.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › includes
Array.prototype.includes() - JavaScript | MDN
The includes() method of Array instances determines whether an array includes a certain value among its entries, returning true or false as appropriate.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array
Array - JavaScript | MDN
5 days ago - The Array object, as with arrays in other programming languages, enables storing a collection of multiple items under a single variable name, and has members for performing common array operations. In JavaScript, arrays aren't primitives but are instead Array objects with the following core characteristics:
🌐
Wikipedia
en.wikipedia.org › wiki › ECMAScript
ECMAScript - Wikipedia
1 week ago - ECMA-262 specifies only language syntax and the semantics of the core application programming interface (API), such as Array, Function, and globalThis, while valid implementations of JavaScript add their own functionality such as input/output and file system handling.
🌐
Flexiple
flexiple.com › javascript › javascript-array-includes
JavaScript Array includes() Method - Flexiple
April 25, 2024 - The JavaScript Array includes() method checks whether an array contains a specified element, returning true if it does and false otherwise.
🌐
W3Schools
w3schools.com › jsref › jsref_includes_array.asp
JavaScript Array includes() Method
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST ... Array[ ] Array( ) at() concat() constructor copyWithin() entries() every() fill() filter() find() findIndex() findLast() findLastIndex() flat() flatMap() forEach() from() includes() indexOf() isArray() join() keys() lastIndexOf() length map() of() pop() prototype push() reduce() reduceRight() rest (...) reverse() shift() slice() some() sort() splice() spread (...) toReversed() toSorted() toSpliced() toString() unshift() values() valueOf() with() JS Boolean
Find elsewhere
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › every
Array.prototype.every() - JavaScript | MDN
6 days ago - A function to execute for each element in the array. It should return a truthy value to indicate the element passes the test, and a falsy value otherwise.
🌐
Built In
builtin.com › software-engineering-perspectives › javascript-array-contains
JavaScript Array Contains: 6 Methods to Find a Value | Built In
Summary: JavaScript offers multiple methods to check if an array contains a value, including indexOf, includes, some, find and findIndex. While indexOf fails with NaN, includes detects it. Object searches use callback functions with some, find and findIndex. more JavaScript offers multiple methods to check if an array contains a value, including indexOf, includes, some, find and findIndex.
Top answer
1 of 16
5530

Modern browsers have Array#includes, which does exactly that and is widely supported by everyone except IE:

console.log(['joe', 'jane', 'mary'].includes('jane')); // true

You can also use Array#indexOf, which is less direct, but doesn't require polyfills for outdated browsers.

console.log(['joe', 'jane', 'mary'].indexOf('jane') >= 0); // true


Many frameworks also offer similar methods:

  • jQuery: $.inArray(value, array, [fromIndex])
  • Underscore.js: _.contains(array, value) (also aliased as _.include and _.includes)
  • Dojo Toolkit: dojo.indexOf(array, value, [fromIndex, findLast])
  • Prototype: array.indexOf(value)
  • MooTools: array.indexOf(value)
  • MochiKit: findValue(array, value)
  • MS Ajax: array.indexOf(value)
  • Ext: Ext.Array.contains(array, value)
  • Lodash: _.includes(array, value, [from]) (is _.contains prior 4.0.0)
  • Ramda: R.includes(value, array)

Notice that some frameworks implement this as a function, while others add the function to the array prototype.

2 of 16
510

Update from 2019: This answer is from 2008 (11 years old!) and is not relevant for modern JS usage. The promised performance improvement was based on a benchmark done in browsers of that time. It might not be relevant to modern JS execution contexts. If you need an easy solution, look for other answers. If you need the best performance, benchmark for yourself in the relevant execution environments.

As others have said, the iteration through the array is probably the best way, but it has been proven that a decreasing while loop is the fastest way to iterate in JavaScript. So you may want to rewrite your code as follows:

function contains(a, obj) {
    var i = a.length;
    while (i--) {
       if (a[i] === obj) {
           return true;
       }
    }
    return false;
}

Of course, you may as well extend Array prototype:

Array.prototype.contains = function(obj) {
    var i = this.length;
    while (i--) {
        if (this[i] === obj) {
            return true;
        }
    }
    return false;
}

And now you can simply use the following:

alert([1, 2, 3].contains(2)); // => true
alert([1, 2, 3].contains('2')); // => false
🌐
Jeffryhouser
jeffryhouser.com › index.cfm › 2022 › 11 › 27 › How-does-the-includes-method-work-on-a-JavaScript-Array-of-Objects
Jeffry Houser's Blog: How does the includes() method work on a JavaScript Array of Objects??
November 27, 2022 - This is because the the target value is pointed at the same object instance that resides inside the array. The comparison is true. Play with a Plunker here. Every once in a while I have a developer conversations and go on a weird tangent, writing a bunch of blog posts to drill into something that should be simple and intuitive. I think this is one of those times, but I'm always happy to explore and share those explorations. This entry was posted on November 27, 2022 at 9:00 AM · posted by Jeffry Houser in JavaScript, Professional | 0 Comments
🌐
NumPy
numpy.org
NumPy
Powerful N-dimensional arrays Fast and versatile, the NumPy vectorization, indexing, and broadcasting concepts are the de-facto standards of array computing today. Numerical computing tools NumPy offers comprehensive mathematical functions, random number generators, linear algebra routines, Fourier transforms, and more.
🌐
DEV Community
dev.to › arnaud › using-array-prototype-includes-vs-set-prototype-has-to-filter-arrays-41fg
Using Array.prototype.includes() vs Set.prototype.has() to filter arrays - DEV Community
July 2, 2020 - Length of values to keep: 1 Length of values to test: 10 includes: 0.207ms has: 0.190ms Length of values to keep: 10 Length of values to test: 100 includes: 0.020ms has: 0.017ms Length of values to keep: 100 Length of values to test: 1000 includes: 0.204ms has: 0.071ms Length of values to keep: 1000 Length of values to test: 10000 includes: 9.942ms has: 1.307ms Length of values to keep: 10000 Length of values to test: 100000 includes: 131.686ms has: 8.016ms Length of values to keep: 100000 Length of values to test: 1000000 includes: 1324.318ms has: 71.495ms · So yes, I am right that with a small quantity of data, Array.includes and Set.has perform roughly the same, but we can see how quickly performance degrades, and the change is so small that it's hard to justify not making it, even for small data samples.
🌐
Career Karma
careerkarma.com › blog › javascript › javascript includes: a step-by-step guide
JavaScript Includes: A Step-By-Step Guide | Career Karma
December 1, 2023 - That’s where the JavaScript includes() function comes in. JavaScript includes() is a built-in function that can be used to determine whether an array contains a particular item.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-check-if-an-array-includes-an-object-in-javascript
How to check if an array includes an object in JavaScript ? - GeeksforGeeks
Check if an array includes an object in JavaScript, which refers to determining whether a specific object is present within an array.
Published   July 11, 2025
🌐
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…
🌐
JsCraft
js-craft.io › home › javascript includes() multiple values
Javascript includes() multiple values
June 25, 2024 - The Javascript array includes() function will return true if a value is found in an array or false otherwise.
🌐
Mimo
mimo.org › glossary › javascript › includes-method
JavaScript includes() method: Syntax, Usage, and Examples
The includes() method in JavaScript checks whether a given value exists in a string or array. This functionality is particularly valuable in modern web development when working with data from HTML elements or applying conditional CSS styles.
🌐
LeetCode
leetcode.com › problems › contains-duplicate
Contains Duplicate - LeetCode
Can you solve this real interview question? Contains Duplicate - Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.