Open In App

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:



Return Value: This method returns the converted array.

Example 1:




// Requiring the lodash library  
const _ = require("lodash");  
      
// Use of _.toArray() method 
console.log(_.toArray(null)); 
console.log(_.toArray('gfg'));

Output:

[]
['g', 'f', 'g']

Example 2:  




// Requiring the lodash library  
const _ = require("lodash");  
      
// Use of _.toArray() method 
console.log(_.toArray(10)); 
console.log(_.toArray({ 'html': 1, 
    'css': 2, 'javascript': 3 }));

 
Output:

[]
[1, 2, 3]
Article Tags :