I am creating a script that would show the keys of my array, in the first attempt worked perfectly, but when I added but a while block, he did not execute and returned this error:
classificacao-v2.js:128 Uncaught TypeError: Cannot read property 'Period' of undefined at classificacao-v2.js:128 Realizing that my problem was in the variable 'n' that appeared as undefined, so I created other variables with different names for each structure. I wonder if it is possible to rewrite it more efficiently without having to repeat each block.
let GoldemStates = [{Period: ' 1°',Points:'300'}, {Period: ' 2°',Points:'250'}, {Period: ' 3°', Points:'155'}] let Chicago = [{Period: ' 1°',Points:'100'}, {Period: ' 2°',Points:'420'}, {Period: ' 3°', Points:'350'}] let Broklyn = [{Period: ' 1°',Points:'300'}, {Period: ' 2°',Points:'250'}, {Period: ' 3°', Points:'155'}] // Show the Teams icons('','Match Results ','div_titulo') let n = 0 icons('golden','Golden States', 'destaque_golden') //Team Title (Symbol, Team Name, CSS) //Goldem States Statistics do { icons('clock',GoldemStates[n].Period + ' Period | ' + 'Points ' + GoldemStates[n].Points ,'texto') // // Show period and points n ++ } while (n < GoldemStates.length); let d = 0 // <-------- CHANGE WHICH WOULD NEED //Chicago Bulls Statistics icones('bulls','Chicago Bulls', 'destaque_bulls')//Team Title (Symbol, Team Name, CSS) do { icons('clock',Chicago[d].Period + ' Period | ' + 'Points ' + Chicago[d].Points ,'texto')// Show period and points d ++ } while (d < Chicago.length); 