How To Check Array Is Empty Or Null In JavaScript

<script src="https://code.jquery.com/jquery-3.5.0.min.js"></script>
<script type="text/javascript">
var Array1 = [1, 2, 3];
var Array2 = [];
console.log(jQuery.isEmptyObject(Array1)); // returns false
console.log(jQuery.isEmptyObject(Array2)); // returns true
</script>
<script type="text/javascript"> 
var undefinedAray = undefined;
if (typeof undefinedAray !== "undefined" && undefinedAray.length > 0) {
// undefinedAray is not empty
} else {
// undefinedAray is empty or undefined
}
</script>
<script type="text/javascript">
var Arraylegnth = [1];
if (Arraylegnth && Arraylegnth.length > 0) {
// Arraylegnth is not empty
} else {
// Arraylegnth is empty
}
</script>

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Websolutionstuff

Websolutionstuff

96 Followers

I am Laravel and PHP Developer. I have also Good Knowledge of JavaScript, jQuery, Bootstrap and REST API.