JS - Object Handling

1. Given an array of objects with 3 key-value pairs, how do we remove a specific key-value pair from each object?

We can make use of map and object destructing to achieve this:

Solution:
const posts = [
  { title: 'Cool', date: '2023', content: 'Happy New Year' },
  { title: 'Awesome', date: '2022', content: 'Happy National Day' },
  { title: 'Dope', date: '2014', content: 'Merry Christmas' },
];
 
const filteredPost = posts.map((obj) => {
  const { date, ...rest } = obj;
  return rest;
});

This will be the output:

Output
[
  { title: 'Cool', content: 'Happy New Year' },
  { title: 'Awesome', content: 'Happy National Day' },
  { title: 'Dope', content: 'Merry Christmas' },
];