I have the following code: teams = []; teams[0] = new Object(); teams[0].name = "Man Utd"; teams[0] = []; teams[0][0] = new Object(); teams[0][0].wins = 2; teams[0][0].defeats = []; teams[0][0].defeats[0] = [3,9,2,1]; teams[0][0].pts = 4; teams[1] = new Object(); teams[1].name = "Man City"; teams[1] = []; teams[1][0] = new Object(); teams[1][0].wins = 2; teams[1][0].defeats = []; teams[1][0].defeats[0] = [8,7,3]; teams[1][0].pts = 12; How can I search for the array defeats for each team but substitute the word defeat with a numerical value?
Have you tried a map? let teams = []; teams[0] = { name: "Man Utd", wins: 2, defeats: [[3, 9, 2]], pts: 4 }; teams[1] = { name: "Man City", wins: 2, defeats: [[9, 7, 3]], pts: 12 }; const reworked = teams.map((row) => {...row, defeats: row.defeats[0]}; Code (JavaScript):
Thanks for the reply, but using this code I am not sure what to do or how to see the new information. If I use document.write on reworked nothing appears.
ofcourse not, it's still an array. You need to update your output code to use the new version of the array.