Comments (18)
Comment written by guy on 08/27/2019 15:35:32
Uhm, a little slip here:
Array.from(new Set(['one', 'two'])); // => ['one', 'two', 'three']
Unless there's a new feature I'm unaware of :)
from dmitripavlutin.com-comments.
Comment written by Dmitri Pavlutin on 08/27/2019 15:48:09
Nice catch! I will fix the example.
from dmitripavlutin.com-comments.
Comment written by Joshua Baker on 08/28/2019 00:23:47
In 4.2, your example's lambda function is () => value, but value was not defined. Did you mean init?
from dmitripavlutin.com-comments.
Comment written by Patrick John Haskins on 08/28/2019 06:52:29
I'm typing from my phone, so I can't test this to be sure, but I believe your deepCopy()
in #3 will not perform a true deep copy. It will effectively deep copy multi-dimensional arrays of immutable values. When it encounters an object, though, it will only copy the reference to the object.
from dmitripavlutin.com-comments.
Comment written by Dmitri Pavlutin on 08/28/2019 07:03:44
Yep, it will deep copy only the array objects.
I updated the text to be more clear.
from dmitripavlutin.com-comments.
Comment written by Dmitri Pavlutin on 08/28/2019 07:03:51
Fixed.
from dmitripavlutin.com-comments.
Comment written by Yevgen Gorbunkov on 08/28/2019 15:07:31
Wouldn't most of the above use cases be solved in a bit more concise manner with
spread operator (...)?
from dmitripavlutin.com-comments.
Comment written by Dmitri Pavlutin on 08/28/2019 15:15:10
What exact use cases are you referring to? Please elaborate.
You can only use spread operator as an alternative of Array.from() to clone an array or to remove duplicates.
from dmitripavlutin.com-comments.
Comment written by Yevgen Gorbunkov on 08/29/2019 15:44:38
Double object property values; Set/Map/NodeList into array; Shallow array copy; Fill array with values/objects; Range of numbers; Unique entries
from dmitripavlutin.com-comments.
Comment written by Yevgen Gorbunkov on 08/30/2019 12:36:58
Check out this collection of codepens
from dmitripavlutin.com-comments.
Comment written by Dmitri Pavlutin on 08/30/2019 13:31:58
Thanks for providing the demos. Sure, you can use spread operator as an alternative if you'd like.
from dmitripavlutin.com-comments.
Comment written by Masha I. Klachko-Blair on 09/27/2019 19:15:27
To me, spread operators are super unreadable. Array.from() is much easier to read and understand.
from dmitripavlutin.com-comments.
Comment written by Dmitri Pavlutin on 09/28/2019 14:04:28
It's a matter of taste. I'm ok with using the spread operator.
But I like to use Array.from() when I need the map function of it.
from dmitripavlutin.com-comments.
Comment written by Waheed Afolabi on 10/07/2019 10:23:50
Nice article. It's really helpful.
Seems Array.from( ) clones an array including nested ones without using the recursiveClone() function...
const nestedArray = [[1, 2, 3], ['one', 'two', 'three']];
function recursiveClone(val) {
return Array.isArray(val) ? Array.from(val, recursiveClone) : val;
}
const nestedArrayCloneUsingFunc = recursiveClone(nestedArray);
const nestedArrayClone = Array.from(nestedArray);
nestedArrayCloneUsingFunc; // [[1, 2, 3], ['one', 'two', 'three']]
nestedArrayClone; // [[1, 2, 3], ['one', 'two', 'three']]
from dmitripavlutin.com-comments.
Comment written by Dmitri Pavlutin on 10/07/2019 11:17:35
Array.from() does only a shallow copy of the array.
Regarding your example: nestedArray[0] === nestedArrayClone[0]
equals to true
, which means that nestedArrayClone
is a shallow copy of nestedArray
.
from dmitripavlutin.com-comments.
Comment written by Waheed Afolabi on 10/08/2019 15:54:18
Oh! Now I know and understand the difference...thanks!
from dmitripavlutin.com-comments.
Could you plz explain, the parameters passed in Array.from() in
#5-generate-ranges-of-numbers.
from dmitripavlutin.com-comments.
Thank you!
It was something I was looking for and couldn't find.
I hope to try everything thoroughly soon.
from dmitripavlutin.com-comments.
Related Issues (20)
- react-usememo-hook/ HOT 12
- javascript-json-modules/ HOT 7
- javascript-import-meta/ HOT 3
- javascript-array-group/ HOT 16
- javascript-array-flatmap/ HOT 23
- interface-vs-implementation/ HOT 11
- vue-next-tick/ HOT 4
- props-destructure-vue-composition/ HOT 7
- ref-reactive-differences-vue/ HOT 5
- environment-variables-javascript/ HOT 3
- ref-in-vue/ HOT 1
- typescript-function-type/ HOT 5
- vue-v-model-form-inputs/ HOT 2
- react-forwardref/ HOT 4
- javascript-enum/ HOT 19
- react-comments/ HOT 8
- typescript-record/ HOT 10
- screen-window-page-sizes/ HOT 3
- javascript-pure-function/ HOT 1
- Great article
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dmitripavlutin.com-comments.