[JavaScript] How to check if given array is empty?
I want to check if the given array is empty, how to do that in Javascript?
1 Answer
4 years ago by Jahaan
We can determine if the given array is empty or not using .length property. array.length returns 0 if the array is empty.
let colours = ['red', 'green', 'blue'];
let emptyArray = [ ];
console.log(colours.length); // outputs 3
console.log(emptyArray.length) // outputs 0
Run the above code online here : https://onecompiler.com/javascript/3xn76zjb7
4 years ago by Meera