Lodash _.toArray() Method
Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc.
The _.toArray() method is used to convert the given value to an array.
Syntax:
_.toArray( value )
Parameters: This method accepts a single parameter as mentioned above and described below:
- value: This parameter holds the value to convert.
Return Value: This method returns the converted array.
Example 1:
Javascript
const _ = require( "lodash" );
console.log(_.toArray( null ));
console.log(_.toArray( 'gfg' ));
|
Output:
[]
['g', 'f', 'g']
Example 2:
Javascript
const _ = require( "lodash" );
console.log(_.toArray(10));
console.log(_.toArray({ 'html' : 1,
'css' : 2, 'javascript' : 3 }));
|
Output:
[]
[1, 2, 3]
Last Updated :
03 Sep, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...