Posted inJavaScript

javascript array contains – How to Check if an Array Contains a Value in Javascript?

javascript array contains – The includes() method returns true if an array contains a specified value. Example with Array contains a primitive value and Array contains an object Determine whether an array contains a value.

javascript array contains & JavaScript Array includes() Method

Checking if an Array Contains a Value in JavaScript also jQuery has a utility function $.inArray(value, array).

Check if an array contains a string

const players = ['rohit', 'virat', 'dhavan'];
const result = players.includes('rohit');

console.log(result); // true

Check if an array contains a number

const ranks = [1,2,3,4,5];

let result = ranks.includes(4); 
console.log(result); // true

result = ranks.includes(6); 
console.log(result); // false

Check if an array contains an object

const blog = {
    'name': 'blog Dev',
    'email': '[email protected]'
const pakainfo = {
    'name': 'pakainfo dev',
    'email': '[email protected]'

const list = [blog, pakainfo];
let result = list.includes(blog);

console.log(result); // true

JavaScript Array includes()

const websites = ["Infinityknow", "blogspot", "w3school", "Pakainfo"];

Start the search at position 3:

const websites = ["Infinityknow", "blogspot", "w3school", "Pakainfo"];
websites.includes("Infinityknow", 3);

check if an array includes a value in JavaScript

console.log(['w3diy', 'pakainfo', 'blogspot'].includes('pakainfo')); //true

jQuery has a utility function

$.inArray(value, array)

Don’t Miss : JavaScript InArray Check If Value Exists

JavaScript Array Contains Example

var res = Array();
if (res.contains('pakainfo')) {
   // do something special

I hope you get an idea about javascript array contains.
I would like to have feedback on my
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype