Search code examples
javascriptobjectlodash

How to get object values from lodash?


say I have this most basic object

var x = {
    a: 1,
    b: 2,
    c: 3,
    d: 4
}

if I do this Object.values(x) this returns me an array of the values [1, 2, 3, 4]

how can I do this in lodash?

I know i can use get

_.get(x)

is just returning me undefined. I want the same thing as Object.values returns me but using lodash


Solution

  • Use _.values

    var x = {a: 1,b: 2,c: 3,d: 4};
    
    var result = _.values(x);
    console.log(result);
    <script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.js"></script>