How to use the values function from lodash

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

lodash.values returns an array of values from an object in the order of their properties.

3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
 * @category Objects
 * @param {Object} object The object to inspect.
 * @returns {Array} Returns an array of property values.
 * @example
 *
 * _.values({ 'one': 1, 'two': 2, 'three': 3 });
 * // => [1, 2, 3] (property order is not guaranteed across environments)
 */
function values(object) {
  var index = -1,
fork icon73
star icon711
watch icon29

426
427
428
429
430
431
432
433
434
435
module.exports.update              = _.update;
module.exports.updatePath          = _.updatePath;
module.exports.updateWith          = _.updateWith;
module.exports.upperCase           = _.upperCase;
module.exports.upperFirst          = _.upperFirst;
module.exports.values              = _.values;
module.exports.valuesAt            = _.valuesAt;
module.exports.valuesIn            = _.valuesIn;
module.exports.walk                = _.walk;
module.exports.weave               = _.weave;
fork icon19
star icon122
watch icon0

+ 92 other calls in file

How does lodash.values work?

lodash.values is a function provided by the Lodash library that takes an object as input and returns an array of the values of its enumerable properties in the same order as the for...in loop would. When you pass an object to lodash.values, it loops through its enumerable properties using a for...in loop, and pushes the values of each property to an array that it returns when the loop finishes. The returned array contains only the values of the object's own enumerable properties, not those inherited from its prototype chain.

148
149
150
151
152
153
154
155
156
157
    remainingCash -= payout;
  });
  /* jshint loopfunc:false */
}

var stakesAndPayouts = _.values(payoutsByEquityStake);


// Liquidation preferences satisfied.  Any remaining payouts now go by percentage ownership in the last round
if (remainingCash > 0) {
fork icon15
star icon79
watch icon4

1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
 * @param {String} winchallengeIdners the challenge ID
 */
async function validateWinners(winners, challengeId) {
  const challengeResources = await helper.getChallengeResources(challengeId);
  const registrants = _.filter(challengeResources, (r) => r.roleId === config.SUBMITTER_ROLE_ID);
  for (const prizeType of _.values(constants.prizeSetTypes)) {
    const filteredWinners = _.filter(winners, (w) => w.type === prizeType);
    for (const winner of filteredWinners) {
      if (!_.find(registrants, (r) => _.toString(r.memberId) === _.toString(winner.userId))) {
        throw new errors.BadRequestError(
fork icon45
star icon17
watch icon0

Ai Example

1
2
3
4
5
6
7
8
9
10
const _ = require("lodash");

const myObj = {
  name: "John",
  age: 30,
  city: "New York",
};

const values = _.values(myObj);
console.log(values); // ['John', 30, 'New York']

In this example, lodash.values is used to extract the values of an object and return them in an array. The myObj object has three key-value pairs, and the _.values function takes the object as an argument and returns an array containing the values of those key-value pairs. The resulting values array contains the values ['John', 30, 'New York'], which correspond to the values of the name, age, and city keys in the original object.

85
86
87
88
89
90
91
92
93
94

  this.processSingle();
}

VoxelTool.prototype.processSingle = function() {
  const intersectionVoxels = _.values(this.voxelGrid.intersectionVoxels);
  const intersection = this.raycaster.intersectObjects(intersectionVoxels)[0];

  if (!intersection) {
    return;
fork icon1
star icon1
watch icon0

730
731
732
733
734
735
736
737
738
739
740
741
742
console.log(update); // => { 'a': [{ 'b': { 'c': 9 } }] }


const updateWith = _.updateWith({ 'a': [{ 'b': { 'c': 3 } }] }, 'a[0].b.c', n => n * n, Object);
console.log(updateWith); // => { 'a': [{ 'b': { 'c': 9 } }] }


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


const valuesIn = _.valuesIn({ 'a': 1, 'b': 2, 'c': 3 });
console.log(valuesIn); // => [1, 2, 3]
fork icon0
star icon4
watch icon0

+ 15 other calls in file

110
111
112
113
114
115
116
117
118
119

var groupChildren = main.groupChildren = function (nodes) {
  nodes = _.groupBy(nodes, function (node) {
    return previousIndexClose(node, nodes)
  })
  return _.values(nodes)
}

/** searches preceeding nodes for pattern */
var searchLink = main.searchLink = function (subNodes, pattern) {
fork icon0
star icon1
watch icon2

167
168
169
170
171
172
173
174
175
  logger.info(`The forums are created only for the active self-service challenges.`)
  return
}

const { body: project } = await topcoderApi.getProject(challenge.projectId)
const allProjectRoles = _.values(constants.TOPCODER.PROJECT_ROLES)
const members = _.filter(project.members, member => {
  return _.includes(allProjectRoles, member.role)
})
fork icon3
star icon0
watch icon14

+ 6 other calls in file

572
573
574
575
576
577
578
579
580
581
}
if (row.state === rowState.added) {
    return this.sqlConn.getInsertCommand(
        row.table.postingTable(),
        row.table.getPostingColumnsNames(_.keys(r)),
        _.values(r));
}
if (row.state === rowState.deleted) {
    return this.sqlConn.getDeleteCommand(
        {
fork icon1
star icon0
watch icon1

+ 95 other calls in file

42
43
44
45
46
47
48
49
50
51
52
53
delete elementUi.Message


/*
* element 的组件
* */
const eleComponents = _.values(elementUi)


/*
* td-addon自定义的组件,在此添加组件
* */
fork icon0
star icon0
watch icon1

+ 17 other calls in file

633
634
635
636
637
638
639
640
641
table.describeTable(function (err, data) {
  if (err) {
    return callback(err);
  }

  var missing = _.values(internals.findMissingGlobalIndexes(table, data));
  if (_.isEmpty(missing)) {
    return callback();
  }
fork icon0
star icon0
watch icon1

357
358
359
360
361
362
363
364
365
366
});

_.each(preferred, function (versions, id) {
  if (_.size(versions) === 1) {
    let oversion = Object.keys(versions)[0];
    versions = _.values(versions); //?
    //assert(_.isUndefined(versions[0]) || versions[0] === true,
    //  'Preferred not true in "' + id + '"');
    if (versions[0] === false) {
      let swagger = specs[id.replace(':','/')+'/'+oversion+'/swagger.yaml'];
fork icon0
star icon0
watch icon5

+ 3 other calls in file

643
644
645
646
647
648
649
650
651
652
      shared.push(obj2);
    }
    return;
  }
  seen.push(obj2);
  (_.isArray(obj2) ? obj2 : _.values(obj2)).forEach(scanForShared);
}
scanForShared(obj);
const getIndent = (count) => "  ".repeat(count);
let indentCount = 0;
fork icon0
star icon0
watch icon0

+ 3 other calls in file

255
256
257
258
259
260
261
262
263
264
        }
    }
}

_formatBrowse(inputSettings, context) {
    let settings = _.values(inputSettings);
    // CASE: no context passed (functional call)
    if (!context) {
        return Promise.resolve(settings.filter((setting) => {
            return setting.group === 'site';
fork icon0
star icon0
watch icon0

+ 4 other calls in file

567
568
569
570
571
572
573
574
575
576
            if (!_.isNil(parentNode)) {
                parentNode.appendChild(node);
            }
        }
    });
    const roots = _.values(dic).filter((n) => n.isRoot);
    return Forest.fromRoots(roots);
}

/**
fork icon0
star icon0
watch icon2

340
341
342
343
344
345
346
347
348
349
filterValues[primaryKey] = (filterValues && filterValues[primaryKey]) ? filterValues[primaryKey] : 0;

// make insert sql command
const keys = _.keys(filterValues);
const question = _.map(keys, () => '?').join(',');
const finalValues = _.values(filterValues);
const sqlcmd = `INSERT INTO \`${tableName}\`(\`${keys.join('\`,\`')}\`) VALUES(${question})`;

// query database
try {
fork icon0
star icon0
watch icon1

+ 3 other calls in file

337
338
339
340
341
342
343
344
345
346
}

console.log(`w1: ${JSON.stringify(w1)}`);

const id_ = weight2id[w1.weight];
const wb = _.values(wm[id_]);

console.log(`id_: ${id_}, wb: ${JSON.stringify(wb)}`);

const w2 = rollWeights(wb);
fork icon0
star icon0
watch icon0

142
143
144
145
146
147
148
149
150
151
    "La date de début ne peut être suppérieur ala date de fin.";
  return response.json(messageJson);
}
try {
  db.query(
    "INSERT into evenements(nom_event, organisator, datdeb, datfin) values(?,?,?,?)",
    [
      nom,
      organisator,
      datedeb.toLocaleDateString("en-ZA"),
fork icon0
star icon0
watch icon1

+ 2 other calls in file

43
44
45
46
47
48
49
50
51
52
    return self._data[prop] !== self._dataOld[prop];
  }).concat(self._model.predefinedCols);
},

getColumnValues: function () {
  return _.values(this._data);
},

excludeFromResult: function (columnName) {
  var self = this;
fork icon0
star icon0
watch icon1

7
8
9
10
11
12
13
14
15
16

findStudents() {
	// group by student
	let obj = this.csvObj.filter((e) => e.NOM_ANNEE);
	obj = lodash.groupBy(obj, "CODE_APPRENANT");
	obj = lodash.values(obj);
	return obj;
}

studentGroupByYear() {
fork icon0
star icon0
watch icon1

Other functions in lodash

Sorted by popularity

function icon

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