I have a custom array structure within my component that includes a name paired with another array indicating the number of times the name has been selected.
I am facing difficulty in extracting the length of the second nested array or using something like Array.length on it.
Below is the current structure of the logged out Array:
0: (2) ["Elliott Lester", Array(4)]
1: (2) ["Frank Miller", Array(3)]
2: (2) ["Adam McKay", Array(3)]
3: (2) ["Zola", Array(3)]
4: (2) ["Saul Metzstein", Array(3)]
5: (2) ["Baltasar Kormákur", Array(2)]
6: (2) ["J.A. Bayona", Array(2)]
7: (2) ["Katsuhiro Ôtomo", Array(1)]
8: (2) ["Darren Aronofsky", Array(1)]
9: (2) ["Alex Proyas", Array(1)]
10: (2) ["Andy Humphries", Array(1)]
11: (2) ["Ken Loach", Array(1)]
12: (2) ["Francis Ford Coppola", Array(1)]
13: (2) ["Andrew Stanton", Array(1)]
14: (2) ["Danny Boyle", Array(1)]
length: 15
__proto__: Array(0)
//component code
let data = groupBy(this.mom,'name')
this.data = Object.keys(data);
this.values = Object.keys(data).map(key => data[key]);
const voting = {};
this.data.forEach((key, idx) => voting[key] = this.values[idx])
let votesresults = [];
for (var player in voting) {
votesresults.push([player, voting[player]]);
}
votesresults.sort(function(a,b){
return b[1].length - a[1].length;
});
this.values = votesresults;
console.log(votesresults);
I would like to display the elements as:
Elliott Lester, 4 - but I'm struggling to achieve this. Any help would be appreciated.
I have attempted to bind the length property to the 'values' array like:
{{ values[i].length }} - which only displays the total length of the entire array.
{{ values[i].Array.length }} - even though I knew this wouldn't work, I gave it a shot due to lack of ideas!