Search code examples
javascriptnode.jscolorsgetimagedata

how to print only rgb value in console.log in nodejs get-image colors library?


It's an array of object.I want to print only rgb value so that i can match it with other rgb value in if else statement. plz help.

 Color { _rgb: [ 4, 4, 4, 1, _clipped: false ] }

Solution

  • You can make your constructor function like,

    function MyColor(color) {
        let rgb = color._rgb;
        [this.r, this.g, this.b] = [rgb[0], rgb[1], rgb[2]];
    }
    console.log(new MyColor(color));// MyColor { r: 40, g: 55, b: 67 }