I have an object like this
data = [%{UNIT: [5,6], UNIQUE_KEY: “1234” },%{ITEM: [a,b], YEAR:%{MONTH: [2019,2020]} , UNIQUE_KEY: “2345”},%{UNIQUE_KEY: “4567”, ITEM: [3,4], CODE: [101,102]}]
I want 2 arrays using elixir
arr_keywords = [ “UNIQUE_KEY”, “CODE”, “ITEM”, “YEAR”, “UNIT”] for headers in excel
arr = [ [ “1234”, “”, “”,"", [5,6] ] , [ “2345”, “”, [a,b], {MONTH: [2019,2020]}, “”], [ “4567”, [101,102], [3,4], “”,""]] for data in rows for their respective columns.
Please help me with creating these two arrays.
Unique_key is present in all objects. Other values may vary.
I want to convert this to excel ultimately where first column is unique key and rest columns are accordingly.
In Elixir this is called a list, not an object. When you see square brackets [] you are seeing a list, and when you see this %{}, you are seeing a Map. So, here you have a List of Maps.
Elixir doesn’t have arrays, this is a list containing other lists.
What Elixir as more looking like Arrays, are maps, but they just look alike. You can learn more bout here: