One thing that I love about JavaScript and especially es6 and onward is the possibility to do very cool one-liners.
One of my favorite is:
arrayOfObjects.find(e => e.name === 'my name' && ( e.description = 'your value', true ) );
This let's us find an object
in an Array of objects
and edit its value.
example:
let arrayOfObjects = [
{name: "my name", description: ''},
{name: "another name", description: ''},
]
by running the above one-liner the result would be:
let arrayOfObjects = [
{name: "my name", description: 'your value'},
{name: "another name", description: ''},
]
If multiple objects fit the if condition they will all be changed.
What about you? What's your fav one-liner?
Burlet Mederic
https://mederic.me
https://twitter.com/crimson_med
Top comments (0)