Building Scalable Artificial Intelligence Products with TensorFlow.js
Explore the power of TensorFlow.js; an open-source library that enables developers to define, train, and deploy machine learning models entirely in the browser and on Node.js.
Hello everyone, welcome to a new devspedia story. Today's story is small, and straight to the point, here are a few JavaScript native functions that you maybe missing or didn't know exists.
We often use .trim();
with strings in order to trim whitespaces, however, there is also .trimStart();
and .trimEnd();
to trim white spaces at the beginning or the end of a string.
We have always used lodash to flatten an array, however, an array natively has 2 functions for this purpose, .flat();
and .flatMap();
, you can use .flat
to flatten an array of arrays, or .flatMap
to flatten an array of basically anything, as it take a function parameter, and behaves very similar to .map();
.
To create an object from a hashmap (ex: const a = [ ['a', 1], ['b', 2] ]
) you can easily pass this hashmap to const b = Object.fromEntries(a);
and it'll return "a": 1, "b": 2;
You can reverse that by passing this result object to Object.entries(b);
which will give you [ ['a', 1], ['b', 2] ]
again.
That's all, thanks for reading devspedia, I love you, and I'll see you the next time :)
References: