Navigate back to the homepage

How to Check if value exists in array JavaScript, php

JavaScript, PHP
October 11th, 2020 · 1 min read

Hello Friends,

Welcome To Infinitbility!

How to Check if value exists in array using indexOf for javascript and in_array for php.

we are going to discuss today’s topic “How to find and specific item on an array without loops in javascript and PHP.”

Let’s begins with Javascript


Javascript provides indexOf function to find value from an array Understand with an example

1//indexOf example
2var fruits = ['Banana', 'Blackcurrant', 'Blueberry', 'Chili pepper', 'Cranberry', 'Eggplant', 'Gooseberry'];
4// You get their index ( Key )
5var index = fruits.indexOf('Blueberry');
6// output 2
8// if value not available
9var index = fruits.indexOf('Apple');
10// output -1


Similarly, Php provides in_array function to find value from an array Understand with an example

3# inArray example
4$fruits = ['Banana', 'Blackcurrant', 'Blueberry', 'Chili pepper', 'Cranberry', 'Eggplant', 'Gooseberry'];
6# You get true or false
7$result = in_array("Blueberry", $fruits);
8# output true
10# if value not available
11$result = in_array("Apple", $fruits);
12# output false

Thanks for reading…

Follow me on Twitter

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo Photoshop Guide



More articles from Infinitbility

How to exit from initramfs busybox in Ubuntu

here you get solution of busybox initramfs issue in ubuntu

October 11th, 2020 · 1 min read

Laravel call function from another class

here you will learn to call a function from another controller.

October 11th, 2020 · 1 min read
© 2020–2022 Infinitbility
Link to $ to $ to $ to $ to $ to $mailto:[email protected]