You need to compare each items in the array:
var pixel = context.getImageData(j,k,1,1).data; // cache array
if (pixel[0] === 0 && // R
pixel[1] === 0 && // G
pixel[2] === 0 && // B
pixel[3] === 0) { // A
...
}
Better yet, not use getImageData()
for each pixel but cache it before starting the iterations:
var x, y,
buffer = context.getImageData(0, 0, 300, 300).data;
for(y = 0; i < 300; y++) {
for(x = 0; x < 300; x++) {
var pos = (y * 300 + x) * 4;
if (buffer[pos] === 0 && // R
buffer[pos+1] === 0 && // G
buffer[pos+2] === 0 && // B
buffer[pos+3] === 0) { // A
...was black...
}
else {
...was not black...
}
}
}