Currently, I am working with a for loop that extracts data for each user from the matchlistResponsestats object. Once the for loop completes its iterations, I end up with approximately 90 arrays in this format:
["username", kills, assists, deaths]
My goal is to combine and sum up the data from these arrays for each username. Additionally, I want to append a new value at the end of each array indicating the number of arrays merged into that specific username.
for (var i = 0; i < matchArrayTotalPlayer; i++) {
if(matchlistplayers[i].username === username) {
const matchlistplayerkills = matchlistResponsestats.players[i].kills
const matchlistplayerheadshots = matchlistResponsestats.players[i].headshots
const matchlistplayerdeaths = matchlistResponsestats.players[i].deaths
const matchlistplayerusername = matchlistResponsestats.players[i].username
console.log(matchlistResponsestats)
var playermatchstats = [matchlistplayerusername, matchlistplayerkills, matchlistplayerheadshots, matchlistplayerdeaths]
}
The resulting output from the for loop (playermatchstats) takes the form:
["dJadebisi", 17, 5, 19], ["softarlugnt", 16, 8, 22], ["pruttstjert", 1, 0, 5], ["dJadebisi", 16, 4, 8], ["pruttstjert", 10, 0, 15], ["softarlugnt", 9, 1, 20]...
Desired output should resemble this:
["dJadebisi", 33, 9, 27, 2],["softarlugnt", 25, 9, 42, 2], ["pruttstjert", 11, 0, 20, 2]
If anyone could nudge me in the right direction on how to accomplish this task, it would be greatly appreciated.