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.

import React, { Component } from "react";
import { Button, Text, View } from "react-native";

class ClassComponent  extends Component {
  state = { array: []};
  
  checkArray = () => {
    if(this.state.array.length == 0){
      return "Empty Array";
    } else {
      return "Not Empty Array";
    }
  }

  render() {
    return (
      <View>
        <Text>{this.state.array.length == 0 ? "Empty" : "Not Empty"}!</Text>
        <Text>{this.checkArray()}!</Text>
      </View>
    );
  }
}


export default ClassComponent;

Output

Add object in array, Example

Thanks for reading…