Best approach to access an array within mapped data?

Hi everyone!

I would like to use Inputs.table() to render array data within a ‘mapped’ (grouped?) data structure. Data started as a simple data, but I applied d3.group() to see how many active projects I’ve got for each country in my portfolio:

data_grouped = d3.group(data, d => d.Country, d=> d.Status)

here’s the data I’d like to visualize:

Currently, I can achieve this by ‘flattening’ the mapped data using Array.from, but because I have two levels of grouping, I have to do this twice:

nepal_active = Array.from(Array.from(data_grouped)[0][1])[0][1]

… Looking at this code, I imagine that there’s probably a better approach out there??

Here’s a notebook:

Thanks for sharing your insights!

Hi, not sure if this answers your question, but since these are Maps you can access their entries by name:

data_grouped.get('Nepal').get('Active')

That makes it a lot more readable at least. Is this what you were after?

2 Likes

Yes indeed! Thank you!