I came up with the following way to reduce my data:
data = [{ id: 99991, name: "NoData1", title: "No Data" },
{ id: 99992, name: "NoData2", title: "No Data" },
{ id: 99993, name: "NoData3", title: "No Data" }];
var dataMapName = data.reduce((rv, v) => {
rv[v.name] = v;
return rv;
}, {}) : null
Now, if I want to access id, I can enter the following:
var NoData1Id = dataMapName['NoData1'].id
or
var NoData1Id = dataMapName.NoData1.id
However, some of my data has spaces in the name, for example:
data = [{ id: 99991, name: "NoData1", title: "No Data" },
{ id: 99992, name: "NoData2", title: "No Data" },
{ id: 99993, name: "NoData3", title: "No Data" },
{ id: 99994, name: "NoData 4", title: "No Data" },
];
Is there a way to change my function to first remove spaces from the name during shortening so that I can still enter:
var NoData4Id = dataMapName.NoData4.id