score:1

Accepted answer
let data = [
  { name: 'Dhanush', createdAt: '2021/01/13 16:57:53', songs: [] },
  { name: 'Dharma', createdAt: '2021/01/13 17:02:47', songs: [] },
  { name: 'Sachin', createdAt: '2021/01/13 17:30:45', songs: [] },
];

const name = 'Dhanush';

const song = {
  id: 1,
  duration: '5 mins',
  name: 'Bingo',
};
data = data.map(
  (val) => (
    val.name === name ? (val.songs = [...val.songs, song]) : val.songs, val
  )
);
console.log(data);

Related Query

More Query from same tag