I using a json
array in my external js file. This array is declared by some required pages and not using of my all pages. My problem is there is "variable not defined error message" showing when using the pages which is not required this array.
In my case I cannot declare this array to access in all the pages. So may I know is there any possible way to check array is defined or not even its not declared in jQuery
.
I had some experiment with the given answers of this question. But I couldn't figure this out.
This is my code from JS file:
// var myArray={}
// if(myArray){
// if( typeof myArray !== 'undefined' || myArray !== null ){
if( myArray !== 'undefined' || myArray !== null ){
var obj = JSON.parse(JSON.stringify(myArray));
var initialPreview;
if(obj.initialPreview) {
var initialPreview = obj.initialPreview;
}
}
Console Error is ncaught ReferenceError: myArray is not defined