In javascript, I have an object that I am trying to pass but not working:
var inf1= { ID: "34343434" };
What I like to do in javascript is to pass this object to a function .
I am not sure how to do this.
I have the calling function as such
function getinf(inf1)
{
var samp = JSON.parse(inf1);
alert(samp.ID);
}
You use
JSON.parse()on a JSON formatted string. You don’t use it on a javascript object. JSON is a text format.Your
inf1variable is already a javascript object so there is no need to parse it.This should work just fine: