This method also functions correctly
console.log(Object.keys(Object.fromEntries([["1", 2],["3", 2],["6", 2]])))
Illustrated in this instance, the Object.fromEntries
function constructs an object using an array of key/value pairs - interpreting the first element as a key and the second element as its corresponding value - resulting in an arrangement as displayed below:
{
"1": 2,
"3": 2,
"6": 2
}
Subsequently, Object.values
is utilized to extract the keys from the previously created object, effectively removing the values while retaining only the keys.
Note: A different approach has been presented for achieving similar results
console.log(Array.from([["1", 2],["3", 2],["6", 2]], x=>x[0]))