How to use the toArray function from lodash

Find comprehensive JavaScript lodash.toArray code examples handpicked from public code repositorys.

4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
 * @category Collections
 * @param {Array|Object|string} collection The collection to convert.
 * @returns {Array} Returns the new converted array.
 * @example
 *
 * (function() { return _.toArray(arguments).slice(1); })(1, 2, 3, 4);
 * // => [2, 3, 4]
 */
function toArray(collection) {
  if (collection && typeof collection.length == 'number') {
fork icon73
star icon711
watch icon29

383
384
385
386
387
388
389
390
391
392
module.exports.third               = _.third;
module.exports.throttle            = _.throttle;
module.exports.thru                = _.thru;
module.exports.times               = _.times;
module.exports.titleCase           = _.titleCase;
module.exports.toArray             = _.toArray;
module.exports.toDash              = _.toDash;
module.exports.toFinite            = _.toFinite;
module.exports.toInteger           = _.toInteger;
module.exports.toLength            = _.toLength;
fork icon19
star icon122
watch icon0

+ 92 other calls in file

1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
remote: remote.info(compact),
admins: settings.admins,
peertube : self.peertube.info(compact),
tor: self.torapplications.info(compact),
captcha: {
	ip: _.toArray(captchaip).length,
	all: _.toArray(captchas).length
},

memory: mem,
fork icon33
star icon58
watch icon7

+ 15 other calls in file

5
6
7
8
9
10
11
12
13
14
15
16
function groupToElements(array, n) {
  var lists = _.groupBy(array, function(element, index){
    return Math.floor(index / n);
  });


  return _.toArray(lists);
}


function endsWith(str, suffix) {
  return str.indexOf(suffix, str.length - suffix.length) !== -1;
fork icon12
star icon22
watch icon0

+ 2 other calls in file

2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
// values in the defaulted arg slots.
fnull: function(fun /*, defaults */) {
  var defaults = _.rest(arguments);

  return function(/*args*/) {
    var args = _.toArray(arguments);
    var sz = _.size(defaults);

    for(var i = 0; i < sz; i++) {
      if (!existy(args[i]))
fork icon3
star icon2
watch icon1

+ 117 other calls in file

506
507
508
509
510
511
512
513
514
515
516
517
518
console.log(lt); // => true


const lte = _.lte(1, 1);
console.log(lte); // => true


const toArray = _.toArray({ 'a': 1, 'b': 2 });
console.log(toArray); // => [1, 2]


const toFinite = _.toFinite(3.2);
console.log(toFinite); // => 3.2
fork icon0
star icon4
watch icon0

+ 15 other calls in file

688
689
690
691
692
693
694
695
696
    }
  }
  //if fromTag exists, then apply mapping filter else don't
  if (fromTag) {
    //append matchingDataSet results together to an array
    matchingDataSet = _.toArray(_.extend(matchingDataSet, generatorUtils.getFilteredSet(toData, toTagColumn, fromTag)));
  }

});
fork icon0
star icon2
watch icon0

+ 5 other calls in file

606
607
608
609
610
611
612
613
614
615

// If we passed in an id instead of a model, get the model
// then check the permissions
if (_.isNumber(postModelOrId) || _.isString(postModelOrId)) {
    // Grab the original args without the first one
    origArgs = _.toArray(arguments).slice(1);
    // Get the actual post model
    return this.findOne({id: postModelOrId, status: 'all'}).then(function then(foundPostModel) {
        // Build up the original args but substitute with actual model
        var newArgs = [foundPostModel].concat(origArgs);
fork icon0
star icon1
watch icon2

8
9
10
11
12
13
14
15
16
17
18
19
 */
const _ = require('lodash');


function unsplat (f) {
  return function () {
    return f.call(null, _.toArray(arguments));
  };
}


const joinElements = unsplat( str => str.join(' '));
fork icon0
star icon1
watch icon0

135
136
137
138
139
140
141
142
143
144
    return true;
}

if (_.isString(commentModelOrId)) {
    // Grab the original args without the first one
    const origArgs = _.toArray(arguments).slice(1);

    // Get the actual comment model
    return this.findOne({
        id: commentModelOrId
fork icon0
star icon0
watch icon1

+ 2 other calls in file

134
135
136
137
138
139
140
141
142
143
144
// => Logs 'later' after one second.


//_.flip(func)
//creates a function that invokes func with arguments reversed.
var flipped = _.flip(function () {
    return _.toArray(arguments);
});
var flipped1 = flipped('a', 'b', 'c', 'd');
console.log('flipped1--->', flipped1);
//flipped1---> [ 'd', 'c', 'b', 'a' ]
fork icon0
star icon0
watch icon0

+ 3 other calls in file

37
38
39
40
41
42
43
44
45
46
47
48
const maxNotUsingApply = Math.max(...[5, 6, 2, 3, 7]);


// call
function unsplat(fun) {
  return function () {
    return fun.call(null, _.toArray(arguments));
  };
}


let joinElements = unsplat(function (array) {
fork icon0
star icon0
watch icon0

Other functions in lodash

Sorted by popularity

function icon

lodash.get is the most popular function in lodash (7670 examples)