I have a JavaScript function that returns an object. I store that object in myarray object and try to return the matched value using switch . it gives me incorrect results when I return the matched value i.e "undefined"
please read the below code and its comments
parseobjectarray('description') // "undefined"
function parseobjectarray(attribute) {
var returnval;
$(document).ready(function () {
var myArray = new Object();
myArray = ParsePagetags(); // returns an object
switch (attribute) {
case 'description':
returnval = myArray.description;
//alert(returnval); // shows correct result
break;
default:
returnval = "";
}
//alert(returnval); // shows correct result
});
alert(returnval); // shows incorrect result i.e "undefined"
return returnval; // shows incorrect result i.e "undefined"
}
WHY???