'How to map an array to a property [closed]

I have this array with 3 integers. I want to use these integers and make a new array of objects that populate the y variable. I want to have the x as an id variable. How can I do this?

From:

const arr = [6, 9, 2]

To:

const arrOfObjects = [{x: 1, y: 6}, {x: 2, y: 9}, {x: 3, y: 2}]


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source