remove one key in each object of array in javascript

 let source = [

{ name: '111', 'mark': 10 }, { name: '222', 'mark': 100 }, { name: '333', 'mark': 100 } ] ] in above json , remove mark and show name with value only

If you want to remove the "mark" property from each object in the source array and keep only the "name" property with its value, you can use the map method to create a new array with the modified objects. Here's an example:

let source = [ { name: '111', mark: 10 }, { name: '222', mark: 100 }, { name: '333', mark: 100 } ]; let modifiedArray = source.map(item => ({ name: item.name })); console.log(modifiedArray);


javascript
let source = [ { name: '111', mark: 10 }, { name: '222', mark: 100 }, { name: '333', mark: 100 } ]; let modifiedArray = source.map(item => ({ name: item.name })); console.log(modifiedArray);

In the above code, we use the map method on the source array to iterate over each object. For each item, we create a new object with the "name" property and its corresponding value from the original object. The resulting array, modifiedArray, will only contain objects with the "name" property.

Output:

css
[ { name: '111' }, { name: '222' }, { name: '333' }]

Now, the modifiedArray contains objects with only the "name" property and its respective value, and the "mark" property has been removed.

No comments:

Post a Comment

Event listening in react

 How we can listen to som eevents some envents fire like click or automatically user enters into input button , that is event on word type i...