The _.castArray() method is used to cast value into an array if it is not an array.
_.castArray( value )
Parameters: This method accepts single parameter as mentioned above and described below:
- value: This parameter holds the value that need to be inspect.
Return Value: It returns an array with the including value passed in the _.castArray().
Example 1: This example using integer value as a parameter.
const _ = require('lodash') is used to import the lodash library into the file.
Example 2: This example using String, null, and undefined as a parameter.
Example 3: With no parameter, object, and function.
Eample 4: This example using multiple parameters, it will take only the first parameter and with an array, it will just return the same array.