var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
var img = new Image();
img.crossOrigin = 'anonymous';
img.src = 'https://upload.wikimedia.org/wikipedia/commons/thumb/6/6a/JavaScript-logo.png/64px-JavaScript-logo.png';
var obj = {
    id: 1,
    color: [240, 219, 79]
};
console.log(obj.color); // (3) [240, 219, 79]
img.onload = function() {
    ctx.drawImage(img, 0, 0);
    var data = ctx.getImageData(0, 0, canvas.width, canvas.height).data;
    var pixelColor = [data[0], data[1], data[2]];
    console.log(pixelColor); // (3) [240, 219, 79]
    console.log(pixelColor == obj.color); // false
    var objectId = getObjectId(pixelColor);
    console.log(objectId); // undefined
}
function getObjectId(color) {
    if (obj.color == color)
    {
        return obj.id;
    }
  return;
}<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title></title>
</head>
<body>
    <canvas id="canvas" width="64" height="64"></canvas>
</body>
</html>I'm trying to use the pixelColor array assembled from ImageData as an argument for a getObjectId() function that will return the id of an object with the specified color array. Why is the function  returning undefined? And why is the if condition in it unfulfilled?
Edit: added the getter function.
 
    