this.setState({
data: [
...data.slice(0, data.length - 1),
{ ...data[data.length - 1], year: "2141" }
]
});
или гибче
this.setState({
data: data.map((item, index, source) =>
index !== source.length - 1 ? item : { ...item, year: "2141" }
)
});
или справа
this.setState({
data: data.reduceRight(
(acc, item, index) => [
...acc,
index !== 0 ? item : { ...item, year: "2141" }
],
[]
)
});
а можно слева
this.setState({
data: data.reduce(
(acc, item, index, { length }) => [
...acc,
index !== length - 1 ? item : { ...item, year: "2141" }
],
[]
)
});
а можно пофантазировать
this.setState({
data: Array.from(
{ length: data.length },
(n => () => (
n++, n !== data.length - 1 ? data[n] : { ...data[n], year: "2141" }
))(-1)
)
});