javascript find element in array – JavaScript Array find() Method

javascript find element in array – The find() method executes a function for each array element. using arr.includes(obj);, Using indexOf() and Using find() Examples.

javascript find element in array

Best way to find if an item is in a JavaScript array using includes() methods.

using jQuery:

$.inArray(5 + 5, [ "8", "9", "10", 10 + "" ]);

don’t miss : Javascript Find Object In Array By Property Value

Using includes()

const allwebsiteLists = ["pakainfo website", 80, "4 infinity know", "w3diy blog", 80];

Then use includes() to check if the string “pakainfo website” exists in the array:

Read Also:  Age Date of Birth calculation with Counter in javascript

allwebsiteLists.includes("pakainfo website");
allwebsiteLists.includes("pakainfo website", 1);
allwebsiteLists.includes(80);
allwebsiteLists.includes('80');

Free Live Chat for Any Issue

don’t miss : Javascript Array Contains

using Using indexOf()

const allwebsiteLists = ["pakainfo website", 80, "4 infinity know", "w3diy blog", 80];

allwebsiteLists.indexOf("w3diy blog");
allwebsiteLists.indexOf("w3 and schools");
allwebsiteLists.indexOf(80)
allwebsiteLists.indexOf(80, 2);

Using find()

const allwebsiteLists = ["pakainfo website", 80, "4 infinity know", "w3diy blog"];

allwebsiteLists.find(el => el.length < 13);
allwebsiteLists.find((el, idx) => typeof el === "string" && idx === 2);

Download

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