Navigate back to the homepage

How to check array is empty or not in react native?

Infinitbility
React Native
October 20th, 2021 · 1 min read
How to check array is empty or not in react native?

Hello Friends 👋,

Welcome To Infinitbility! ❤️

This tutorial will help you to check an array is empty or not in react native, here you will get an example of checking the empty array in function or in a render function.

we can easily know array is empty or not using array length if the length is 0 it means the array hasn’t any value, it is greater than 0 it means the array has value.

Here you will get an example of checking empty array in functions and in render Component.

1import React, { Component } from "react";
2import { Button, Text, View } from "react-native";
3
4class ClassComponent extends Component {
5 state = { array: []};
6
7 checkArray = () => {
8 if(this.state.array.length == 0){
9 return "Empty Array";
10 } else {
11 return "Not Empty Array";
12 }
13 }
14
15 render() {
16 return (
17 <View>
18 <Text>{this.state.array.length == 0 ? "Empty" : "Not Empty"}!</Text>
19 <Text>{this.checkArray()}!</Text>
20 </View>
21 );
22 }
23}
24
25
26export default ClassComponent;

Output

Add object in array, Example

Thanks for reading…

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

Tutorials

Categories

More articles from Infinitbility

How to add object in array Javascript?

How to add object in array Javascript?

Example of add object in array, in javascript, React, React Native, vue, node, deno, typescript and all javascript framework.

October 19th, 2021 · 1 min read
How to compare two files in vs code?

How to compare two files in vs code?

Visual studio code compare two files example in simple way

October 19th, 2021 · 1 min read
© 2020–2021 Infinitbility
About
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]