Updating and adding a specific value in a object in an array?

I’m trying to change a value in an object in an array, So what i change is so random, this is part of my code :

const [data, setdata] = useState([
    { x: 1, y: 2 },
    { x: 1, y: 2 },
    { x: 1, y: 2 },
  ]);

I want to change whole X and also it can be added, like

the change data can be like this : [3,4,5,6,7,8,9] and length can change.

So i tried to do it like this:

 const updateX = () => {
    setdata(data => [...data.map(d => (d.x = [13, 21, 35, 3, 5, 6, 7]))]);
  };

but it gets error I’d like to know how to solve it. Thank you in advance

what I achieve is like this :

if I change it to [3,4,5,6,7,8,9] then data state should be like this :

[3,4,5,6,7,8,9]

    { x: 3, y: 2 },
    { x: 4, y: 2 },
    { x: 5, y: 2 },
    { x: 6, y: 2 },
    { x: 7, y: 2 },
    { x: 8, y: 2 },
    { x: 9, y: 2 },
    

Answer

Just update like this with spread operator

const updateX = () => {
  setdata((data) => data.map((d) => ({ ...d, x: [13, 21, 35, 3, 5, 6, 7] })));
};

Update:

const newData = [3, 4, 5, 6, 7, 8, 9];

const updateX = () => {
  setdata((data) => data.map((d, i) => ({ ...d, x: newData[i] })));
};