The castArray
function from the Lodash library is used to cast a value into an array. If the value is already an array, it will return the same array. If the value is not an array, it will return a new array with the value as its only element. Here's an example of how to use it:
index.tsx129 chars7 lines
In the example above, the castArray
function is used to convert the value
variable into an array. Since value
is not an array, castArray
returns a new array with the value as the only element.
If you pass an array to castArray
, it will return the same array:
index.tsx121 chars5 lines
In the example above, values
is already an array. castArray
simply returns the same array because it does not need to perform any casting.
gistlibby LogSnag