Last Updated: May 23, 2017
·
270
· 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