

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get the values of an object in JavaScript?
There are some methods such as Object.values() to get the values of an object. But through those methods, the process to find out the values is lengthy. To alleviate this, Underscore.js a library of javascript has provided a method called _.values(). This method requires no for loop to execute the values. It is a direct method to execute the values of an object.
In the following example, the values of an object were executed using the Object.values() method. This method requires a for-loop to execute the values.
Example
<html> <body> <script> var user = { name: "Rahim", designation: "content developer" }; for (let value of Object.values(user)) { document.write(value + "</br>"); } </script> </body> </html>
Output
Rahim content developer
In the following example, the values of an object were executed using _.values() method. Here no for-loop is required. It's a straight forward method.
Example
<html> <body> <script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/0.10.0/lodash.min.js"></script> </head> <body> <script> var res = JSON.stringify(_.values({"name": 'ElonMusk',age: 47, "Organization":'Spacex' })); document.write((res)); </script> </body> </html>
Output
["ElonMusk",47,"Spacex"]
- Related Questions & Answers
- How to get the length of an object in JavaScript?
- How to get Property Descriptors of an Object in JavaScript?
- How to get the first n values of an array in JavaScript?
- Converting a JavaScript object to an array of values - JavaScript
- How to edit values of an object inside an array in a class - JavaScript?
- Filter the properties of an object based on an array and get the filtered object JavaScript
- How to return an array whose elements are the enumerable property values of an object in JavaScript?
- How to get the size of a json object in JavaScript?
- Find n highest values in an object JavaScript
- How to modify key values in an object with JavaScript and remove the underscore?
- How to get the coordinates of an object in a Tkinter canvas?
- Get the number of true/false values in an array using JavaScript?
- How to merge an array with an object where values are arrays - JavaScript
- How to get the values of the different types from a JSON object in Java?
- How to set JavaScript object values dynamically?
Advertisements