Can someone please help me with this. I don't know why the globally defined object 'arr' cant be recognized in the function 'go2', do I need to pass the object through the function 'go2'? Below is my example code.
var arr = {};
function go(){
var id = "id";
var val = 2;
arr[id] = val;
}
function go2(name){
console.log(name);
// can't get this to show the name value which should be 2 defined by 'val which is defined in the 'go' function.
}
setInterval(function(){
var id = "id";
var name = arr[id];
go2(name);
}, 3000);
Edit: I was not calling the go
function as others have pointed out. The code I posted here is a simplified version of what i'm currently working on. I created a fiddle here https://jsfiddle.net/david230/v99pppk1/ to show what i'm working on. The logic is the same, but my fiddle deals with google maps. I'm not able to remove a polyline based on the ID which in this case is the destination coordinates after I draw it using the drawRoute method. The drawnRouteObj is always undefined on line 29.