Navigate back to the homepage

How to check array contains value in react-native?

React Native
January 16th, 2022 · 1 min read
keep affilitate

Hello Friends 👋,

Welcome to Infinitbility.

As a developer, we have many times needed to check values on having array values or not.

Today, we will see how to check array contains a value or not in react native.

To check the value in an array Javascript provides the includes() method, where we can easily able to know array have the same value or not.

Talk is cheap, so me code.

1import React, { useState } from 'react';
2import { Text, View, StyleSheet, TextInput } from 'react-native';
4const users = ['infintbility', 'notebility'];
6export default function App() {
7 const [username, setUserName] = useState('');
8 return (
9 <View style={styles.container}>
10 <TextInput placeholder="username" style={{borderBottomWidth: 1, padding: 10}} onChange={(ev) => setUserName(} />
11 <Text style={styles.paragraph}>{users.includes(username) ? 'Username not available' : 'Available'}</Text>
12 </View>
13 );
16const styles = StyleSheet.create({
17 container: {
18 flex: 1,
19 justifyContent: 'center',
20 backgroundColor: '#ecf0f1',
21 padding: 8,
22 },
23 paragraph: {
24 margin: 24,
25 fontSize: 18,
26 fontWeight: 'bold',
27 textAlign: 'center',
28 },


React Native, array, includes, Example
  • Try it yourself

In the above, exmple I have created the example “When username value already exists in our array then show Username not available

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.

melio affilitate

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 check android version in react native?

React native get android version example.

January 15th, 2022 · 1 min read

How to remove item from json object in javascript?

Javascript, Delete element from object example.

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