There is an array which its items should be the keys of an object. As an example:
['key1', 'key2', 'key3']
is my array. I need to have it like this object:
{
'key1': '',
'key2': '',
'key3': ''
}
As it might be so items in array prefer not to use loops. How can create object without loops?
forloops" or "without any kind of looping through an array"?dict.fromkeys. Your best bet would beObject.fromEntries(keys.map(k => [k, ''])), but that's a loop too.obj = { [arr[0]]: "", [arr[1]]: "", [arr[2]]: "", };That's it.