Undefined value with declared values JavaScript

So here’s the problematic code

var board = [
 {
   grdNbr: 1,
   value: 0,
 },
 {
   grdNbr: 2,
   value: 0,
 },
 { 
   grdNbr: 3,
   value: 0,
 },
 {
   grdNbr: 4,
   value: 0,
 },
 {
   grdNbr: 5,
   value: 0,
 },
 {
   grdNbr: 6,
   value: 0,
 },
 {
   grdNbr: 7,
   value: 0,
 },
 {
   grdNbr: 8,
   value: 0,
 },
 {
   grdNbr: 9,
   value: 0,
 },
]  
                   

I tried declaring objects as arrays, but I don’t really get how it works, so please explain it to me. So, back to the topic. When I check the value it shows undefined (the code is below)

switch(board.grdNbr){

 case 1:
  board.value = 1
  console.log(board.value)
  bg.bg1 = x
  msg.channel.send(boardDRW)
  turn++
  break;
...
}

After that, in the console log the value for value is 1, but before that the value is undefined. Any idea how can I fix this?

19 thoughts on “Undefined value with declared values JavaScript”

Leave a Comment