I have an array that I want to pass to a javascript onclick function. I send that array in the onclick event of a button. The onclick function return me [object Object]. Is there a different way to do call that function with the array?
Here My Code:
var data_type= $.parseJSON(data_playtype[1]);//{"1":"apple","2":"orange","23":"berry","8":"grape","9":"mango"}
str1.push('<td><a href="javascript:void(0)" onClick="showABC(\''+data_type+'\')">'Data'</td>');
function showABC(fruit){
$.each(fruit,function(pid,pt){
alert(pt);
});
}
ptis an object, so when you doalert(pt), it's stringifying the object to[object Object]. Try to access a specific key of that object.onClick, yes?