empty array length code example

Example 1: javascript empty array

arr = [];   // set array=[]

//function
const empty = arr => arr.length = 0;
//example
var arr= [1,2,3,4,5];
empty(arr) // arr=[]

Example 2: isempty for arrays

Object arr[] = new Object[10];
boolean empty = true;
for (Object ob : arr) {
  if (ob != null) {
    empty = false;
    break;
  }
}

Example 3: isempty for arrays

arr = new int[0];
if (arr.length == 0) {
  System.out.println("array is empty");
}

Example 4: empty array javascript

// set array
arr = [1,2,4];

// empty array
arr = [];

Example 5: empty array length javascript

empty array check javascript