Wednesday, June 3, 2026
HomeLanguagesJavascriptLodash _.toArray() Method

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




// 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:  

Javascript




// 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]
RELATED ARTICLES

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6894 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7017 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS