A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript/lodash-_-toarray-method/ below:

Lodash _.toArray() Method - GeeksforGeeks

Lodash _.toArray() Method

Last Updated : 03 Sep, 2020

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:

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]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4