Before anything else, if you are debugging, you are better off using the debugger of the browser (F12 in most browsers). Use console.log()
to output to the console to see values. Breakpoints would be better since they pause code, and you can inspect values at that moment.
Now, for the mistakes you made:
Your
output
istest
which is an<a>
. You can't do apush
since that's not an array. What you can do is create an array, fill it with values, and do aJSON.stringify
to turn it into a string.You should use
document.get*
functions, likedocument.getElementId()
to refer to DOM elements. Though browsers do expose globals for elements withid
s, you should avoid that.
function alterText() {
var myData = {
"timestamps": [1369008000, 1369094400, 1369180800],
"clicks": [1, 2, 3]
};
var output = [];
var link = document.getElementById('test');
for (var i = 0, l = myData.timestamps.length; i < l; i++) {
output.push([myData.timestamps[i], myData.clicks[i]]);
}
// Output to console
console.log(output);
// Convert array to text and output to element
link.innerHTML = JSON.stringify(output);
}