DEV Community

Charlotte Fereday
Charlotte Fereday

Posted on

Visualising documentation: JavaSript array.of

Alt Text

Today’s function is array.of(), mdn description here.

This function creates an array from whatever it has been given. Sounds a lot like array.from() right?

The difference is array.of can take multiple parameters, so works especially well if there are many things to add to the array, i.e. numbers. Whilst array.from can only takes one parameter, so works well especially with a string to split each char into an element in the array.

Another difference between array.from is that if array.of is passed an array and a function it won't apply the function to each element in the array like array.from but instead stores the function in the array.

Would welcome any comments on good situations to use this function.

I've done my own version of the docs with sketches together. Here’s the folder for array.of. Check out the readme to see how you can run the examples.

Top comments (0)