Vue.js check undefined Object or Array


We can use JavaScript typeof operator to check whether an object, array or string is undefined. Here in this tutorial, we are going to explain how you can check undefined objects, array or string in vue.js.


Vue.js check undefined Object or Array JavaScript Example

You can check undefined Object or Array simply as below-

Example:

//check undefined Array
if (typeof myArray === "undefined") {
    alert("myArray is undefined");
}

// check undefined object
if (typeof myObj === "undefined") {
    alert("myObj is undefined");
}

//check object property
if (typeof myObj.some_property === "undefined") {
    alert("some_property is undefined");
}


Advertisements

Add Comment

📖 Read More