1

I'm trying to create an array of color values. I define the color values as objects:

    let rgbPalette = [];
    var color1 = {r: 152, g: 52, b: 211, a: 255};
    rgbPalette.push(color1);
    var color2 = {r: 0, g: 0, b: 0, a: 0};
    rgbPalette.push(color2);

    console.log(rgbPalette);
    

when log the array to the console, i get different property values of the objects:

rgbPalette:  
(2) [{…}, {…}]
0: {r: 151, g: 51, b: 210, a: 255}
1: {r: 0, g: 0, b: 0, a: 8}
length: 2
__proto__: Array(0)

Can anyone help me figure out what is going on here? Thanks.

Pointy
  • 405,095
  • 59
  • 585
  • 614
  • 1
    Your code does not appear to do what you say it does. Perhaps you left out some important details. – Pointy Feb 23 '20 at 03:17
  • Or all of them. – Dave Newton Feb 23 '20 at 03:20
  • Something must be mutating the object before you examine it in the console. (feel free to post a MCVE so there's something to debug and it could be reopened) – CertainPerformance Feb 23 '20 at 03:20
  • ah OK, so I'm calling this function with an 'await' from another asynchronous function. This is being developed in Electron, so it is using a chromium browser. I think the other issue mentioned by @CertainPerformance is similar to what's happening here. But I need to return this array to the async function, so tricking the console won't be enough. Any ideas? – Harry Teitelman Feb 23 '20 at 03:34
  • update: i see, just adding a print line with JSON.stringify in the parent function reveals that the value is being passed correctly. thanks for your help. – Harry Teitelman Feb 23 '20 at 14:40

0 Answers0