DEV Community

Cover image for 7 Must Know JavaScript Tips & Tricks 🎈

7 Must Know JavaScript Tips & Tricks 🎈

Dom (dcode) on September 15, 2022

Let's have a look at 7 valuable tips and tricks found in the most popular language in the world, JavaScript. 1. Destructuring with Parame...
Collapse
 
thomasbnt profile image
Thomas Bnt ☕

Nice !
You can put video embed with :

{% embed https://www.youtube.com/watch?v=oRekCcwSeXs %}

Collapse
 
matijanovosel profile image
Matija Novosel

Excellent post, though for number 5 I'd note that using Set does indeed remove duplicates but only if the array is filled with primitive values.

In the case of an array being filled with objects, however...

const departureTimes = [{"departureTime": "07:00:00"}, {"departureTime": "07:00:00"}, {"departureTime": "13:05:00" }];
const unique = Array.from(new Set(departureTimes)); // [{"departureTime":"07:00:00"},{"departureTime":"07:00:00"},{"departureTime":"13:05:00"}]
Enter fullscreen mode Exit fullscreen mode

A little overkill but In this case something like this could also work:

const unique = Array.from(new Set(departureTimes.map(x => JSON.stringify(x)))).map(x => JSON.parse(x)); // [{"departureTime":"07:00:00"},{"departureTime":"13:05:00"}]
Enter fullscreen mode Exit fullscreen mode
 
orimdominic profile image
Orim Dominic Adah

I don't see how 14 and 16 are 'jurassic' versions. 18 is the latest.
Thanks for the update though

Collapse
 
vhoyer profile image
Vinícius Hoyer

That was exactly what I was going to comment, thanks

 
camiloforero profile image
camiloforero

In production environments, either Active LTS (16) or Maintenance LTS (14) should be used.

Node 18 is not an LTS at all, it's the Current release, and it is not quite fit for production use until the 25th of october, when it will become Active LTS

It's all here: github.com/nodejs/release#release-...

Collapse
 
majklzumberi profile image
majkl zumberi

A deep clone now can be done with the native api structuredClone() it also clone deep nested objects

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

Did you also know that JSON parse and stringify have 2nd arguments, a function for filtering and processing all values

Collapse
 
pranav2580 profile image
Pranav Kumar

Thanks dude it is so amazing ☺️

Collapse
 
orimdominic profile image
Orim Dominic Adah

Structured clone does not work in Node.js

Collapse
 
anirseven profile image
Anirban Majumdar

Thanks for this amazing article

Collapse
 
caominhdev profile image
Cao Quốc Minh

(y)

Collapse
 
mobashir10 profile image
Mo Bashir

If all of these are copy from dcode tutorial what your course will be

Video link:
youtu.be/oRekCcwSeXs