AngularJs check empty array

AngularJs check empty array- It is very simple to check if an array is empty in AngularJs. You can just use the array.length property. Here in this tutorial we are going to explain how you can check if an array is empty. You can use our online demo try and edit the code online.

AngularJs check empty array | Example

array.length property is used to find the array length ie. size of array. It will give 0 if array is having no element.

AngularJs check empty array | Example:

<!DOCTYPE html>
<html lang="en">
 <script src="//"></script>
var myApp = angular.module("myApp", []);
 myApp.controller("myController", function($scope,$timeout) {
 $scope.myArray = [];
 $scope.checkArray = function() {
	 if($scope.myArray.length > 0){
		 // do stuffs
		 alert('Given array is empty!');
<div ng-app="myApp">  
<div ng-controller="myController">  
 <button ng-click='checkArray()' >Check Array</button>


Try it »

If you run the above example it will produce the output something like this –

AngularJs set variable in view


Add Comment

📖 Read More