I have the following JavaScript code snippet:
let array = [];
const datas = [
'name1',
'name2',
'name3',
];
async function getData() {
datas.forEach((data) => {
let myData = data.name;
if(!array.includes(myData)){
array.push(myData);
}
})
let result = await array;
console.log('Result', result);
};
getData();
This code returns an array containing strings like:
['name1','name2', 'name3']
I want to convert each index of the array
into an empty array, so it looks like this:
['name1': [], 'name2': [], 'name3': []]
Is there a way to achieve this using plain JavaScript?