Last Updated: May 23, 2017
·
647
· Codi

How to make an array out of any value (string or other) in Javascript

You can use is array-make open source component to any Javascript value (including string) with an array.

Examples:

makeArray(1) // => [1] makeArray([1]) // => [1] makeArray(null) // => []

It also has 3 tests passed:

makeArray() should wrap an empty string with an array

makeArray() should return an empty array as nil value was passed

makeArray() should return the same array reference if an existing array was passed

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside