loading...
Cover image for What is your favorite one-liner?

What is your favorite one-liner?

crimsonmed profile image Médéric Burlet ・1 min read

One thing that I love about JavaScript and especially es6 and onward is the possibility to do very cool one-liners.

small-code

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.

question

What about you? What's your fav one-liner?


Burlet Mederic
https://mederic.me
https://twitter.com/crimson_med

Posted on by:

crimsonmed profile

Médéric Burlet

@crimsonmed

『  』| Passionate Coder | Idea Hurricane

Discussion

markdown guide