Hi in the following code, how do I remove the previous element from the DOM and replace it with new elements. This should be done everytime I press the button. Currently it keeps adding new elements to the DOM everytime i press the button.
let arr = [
  {name: 'John', age: 31},
  {name: 'Eric', age: 55},
  {name: 'Kyle', age: 80},
  {name: 'Pedro', age: 44},
  {name: 'Ali', age: 35},
];
let btn = document.querySelector('button');
btn.addEventListener('click', () => {
arr.map(info => {
  let p = document.createElement('p');
  let container = document.querySelector('.container');
  if(p === undefined){
    p.remove();
  }
  p.append(info.name);
  container.append(p);
})
})
 
     
     
    