const arr = [
{ id: 1, text: "123" },
{ id: 2, text: "456" },
{ id: 3, text: "789" },
];
For example now its looks like that ^^^, but need to make it smth like that:
const arr = [
{ id: 1, text: "123," },
{ id: 2, text: "456," },
{ id: 3, text: "789." },
];
How can i do it?
Here you go:
const arr = [{
id: 1,
text: "123"
},
{
id: 2,
text: "456"
},
{
id: 3,
text: "789"
},
]
const newArr = arr.map(({
id,
text
}, idx) => ({
id,
text: `${text}${idx < arr.length -1 ? "," : "."}`
}))
console.log(newArr)