EN
JavaScript - transform object into array with lodash
0
points
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>