JSFiddle - React, Tailwind, and code Playground

HTML

<p id="log"></p>
<p id="box"></p>

JavaScript

var blocks = [];

function Block(x, y, z) {
    blocks.push(this);
    this.x = x;
    this.y = y;
    this.z = z;
    this.neighbours = function() {
        var n = 0;
        for (var block in blocks) {
            log(JSON.stringify(block));
            if (block == this) {
                continue;
            }
            if (Math.abs(block.x - this.x) <= 1 && Math.abs(block.y - this.y) <= 1 && Math.abs(block.z - this.z) <= 1) {
                n++;
            }
        }
        return n;
    };
}

var b1 = new Block(0, 0, 0);
var b2 = new Block(0, 1, 0);
document.getElementById("box").innerHTML = b1.neighbours();

function log(message) {
    var target = document.getElementById('log');
    target.innerHTML += message + '<br/>';
}