I have an object that is uses bitwise enumeration. I also have an integer that corresponds to this object. The object may look like so:
let int = 14; // key3 + key4 + key5
let enum {
key1: 0,
key2: 1,
key3: 2,
key4: 4,
key5: 8,
key6: 16,
key7: 32,
key8: 64
// .....
}
// Output: ['key3', 'key4', 'key5'] or something along the lines of this
Because 8 + 4 + 2 = 14, I want to write a function which should return key3, key4, and key5. Is this possible in Javascript? And if so, how is it done? If it's not, how can it be done?
8,4and2beforehand. how do you get those numbers form14?intandenumare reserved identifiers for upcoming version of js.% 2) to generate a 'bit stream' and fill array elements corresponding to the set bits with the canonical power of 2.