Hi, In this blog I am going to show, How to prevent array mutation.

Here, We have an array of objects countries.

let countries = [
{id: 1, name: "India", image: "thumb10.jpg"},
{id: 2, name: "Africa", image: "thumb11.jpg"},
{id: 3, name: "South Africa", image: "thumb12.jpg"},
{id: 4, name: "Bolivia", image: "thumb13.jpg"}
];

Return specific fields from the array

From the countries array, we want only two fields id and name. So we use the array mapping function to get the desired result.

let output = countries.map(s => ({ id: s.id, name: s.name}));
console.log(countries); // there will be no change in array
console.log(output); …


Photo by Unsplash

If you are a developer, you must have faced a certain time when a clock is ticking over your head as your deadline approaches, and you go all out of mind in time of urgency, don’t you?

well if you ever face a need in such time of urgency to extract images from a PPT file in your storage without doing so much of an effort, or facing countless ads on online conversion sites, how about having your own personal little handy tool to do your job just right! …

Kishan Panchal

A self-motivated achiever with an ability to plan and execute.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store