map destructuring javascript code example

Example 1: object destructuring into this

const demo = { nextUrl: 'nextUrl', posts: 'posts' };

const target = {}; // replace target with this

({ nextUrl: target.nextUrl, posts: target.communityPosts } = demo);

console.log(target);

Example 2: array map destructuring

var arr = [
  { name: "Anuja", from: "Saurav" },
  { name: "Saurav", from: "Anuja" },
  { name: "All", from: "All" },
];

arr.map(({ name, from }) => console.log(name, from));