<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script>
function ShowMe(e) {
var c = e.target;
var f = c.textContent;
console.log(f);
}
var a = [1, 2, 3, 4, 5, 6 ,7, 8];
for(var i = 0; i <= a.length; i++){
var b = document.createElement('p');
b.textContent = a[i];
b.onclick = ShowMe;
window.document.body.appendChild(b);
}
</script>
</body>
</html>