data1 = [{name:"sonu",roll:34,file:"asj.jpg"}, {name:"sonu",roll:34,file:"asj1.jpg"},{name:"sonu",roll:34,file:"asj2.jpg"},{name:"dip",roll:67,file:"fgd3.jpg"}, {name:"dip",roll:67,file:"fgd4.jpg"}, {name:"dip",roll:67,file:"fgd5.jpg"}]"datos" json convertir a como "datos2"
data2= [{name:"sonu",roll:34,file:[asj.jpg,asj1.jpg,asj2.jpg]}, {name:"dip",roll:67,file:[fgd3.jpg,fgd.jpg,fgd5.jpg]}]Use Array.reduce() para reducir la primera matriz a lo que desea:
const data = [ { name: "sonu", roll: 34, file: "asj.jpg" }, { name: "sonu", roll: 34, file: "asj1.jpg" }, { name: "sonu", roll: 34, file: "asj2.jpg" }, { name: "dip", roll: 67, file: "fgd3.jpg" }, { name: "dip", roll: 67, file: "fgd4.jpg" }, { name: "dip", roll: 67, file: "fgd5.jpg" } ] const data2 = data.reduce((prev, curr) => { const found = prev.find(o => o.name === curr.name) found ? found.file.push(curr.file) : prev.push({ ...curr, file: [curr.file] }) return prev }, []) console.log(data2);