็Hi guys, I have a serious problem which I try to solve for 2 day straight now. Can you suggest how I can get the result I want from the mock-up code below. I've been asking around in several forums and no one can help me: var a = Math.floor((Math.random()*100)+1); var x = function() { var c = { d: a, e: 'klmn' }, f = JSON.stringify({ type: 'test', data: c }); return f; } var y = function() { var b = [a, 555]; return b; } function callback(i) { var s; if (typeof i === 'string') { var t = i, u = JSON.parse(t); s = u.data.d; } if (typeof i === 'object') { var v = i, w = v[0]; console.log(s); // --> problem is here } } var test = document.getElementById('test'); test.addEventListener('click', function() { callback(x()); callback(y()); }); Code (markup): What I'm doing: Please ignore the random number I just created it to represent the user ID. So every data is appended with the user ID. (I don't know why people pay attention only to this point.) In real life, or in my web app, the user's interact would generate two type of data: an array and a string, in separate functions. For string data I convert it to a JSON format and send it from a browser to a server along with array data in order to process them. The app at the server detects that string data always reaches it first (I don't know why), so I create a function to mock-up that data processing function on the same page because they do pretty much the same thing. My point is I want to match the ID to check if those data come from the same user before I process them. The problem is how do I check that. Note that I can't call the function as callback(x(),y());, which is working, because doing so data would send large data and it would cause Aw, Snap! on Chrome, or Stop Script! on other browsers. Thank you,
Never mind. I solve it: var s, t, u; function callback(i) { if (typeof i === 'string') { return t = i; } if (typeof i === 'object') { u = i; } console.log(u); } Code (markup):