ReactJs check empty Array or Object Example

04-Apr-2023

.

Admin

ReactJs check empty Array or Object Example

Hi Guys,

In this blog, i will show you how to check array is empty or not in reactjs. we will talk about reactjs check empty array example. We can use native JavaScript length property check whether the array or object is empty in Reacjs. In this tutorial, i will explain you empty array is empty or not in reactjs.

Here i will give you full example for how to check array or object is empty or not in reactjs. So let's see the bellow example.

Example


import React from 'react'

export default class Home extends React.Component{

render(){

var myArr = [];

if(myArr.length > 0){

var items = myArr.map((item) =>

<li>{item}</li>

);

}else{

var items = <li>Array is Empty.</li>

}

return(

<div>

{items}

</div>

);

}

}

I hope it will help you...

#React.js