Lodash - castArray method


Advertisements

Syntax

_.castArray(value)

Casts value as an array if it's not one.

Arguments

  • value (*) − The value to inspect.

Output

  • (Array) − Returns the cast array.

Example

var _ = require('lodash');

console.log(_.castArray(1));
console.log(_.castArray({ 'a': 1 }));

Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

Output

[ 1 ]
[ { a: 1 } ]
lodash_lang.htm
Advertisements