Array.prototype.keysbeginnerconst arr = ['a', 'b', 'c']
const keys = arr.keys()
keys.next().value // β 0
keys.next().value // β 1Use keys() to get an iterator that yields the index of each element.
Array.prototype.keys() returns an Array Iterator that yields the index of each element. Because it returns an iterator (not a plain array), you need to convert it with Array.from() or the spread operator to get an actual array.
Challenge: Implement getKeys(arr) that converts arr.keys() to an array of indices.
getKeys(['a', 'b', 'c']) // β [0, 1, 2]
getKeys([]) // β []