Languages
[Edit]
EN

JavaScript - transform object into array with lodash

0 points
Created by:
Dollie-Rutledge
806

In this article, we would like to show you how to transform object into array with lodash in JavaScript.

Quick solution:

var object = { id: 1, name: 'a' };

var array = _.values(object);  // [ 1, 'a' ]

 

Practical example

In this section, we present a practical example of how to convert object values into an array using lodash (_).

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<head>
  <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/underscore@1.13.4/underscore-umd-min.js"></script>
</head>
<body>
  <script>

    var object = { id: 1, name: 'a' };

    var array = _.values(object);  // transforms object to array

    console.log(JSON.stringify(array)); // [ 1, 'a' ]

  </script>
</body>
</html>

 

References

  1. Underscore.js

Alternative titles

  1. JavaScript - transform object to array with underscore
  2. JavaScript - convert object into array with lodash (underscore)
  3. JavaScript - convert object values into array with lodash (underscore)
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join