Ways to implement Object.values() in JavaScript Last Updated : 12 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report There is a method Object.values() which returns the values of JavaScript Object. Here we are going to see all other alternatives to this method with the help of JavaScript. Here a few approaches are discussed. Using Object.keys() method and map() methodUsing obj.hasOwnProperty() and push() method Using Object.keys() method and map() method Approach 1: Use the Object.keys() method to get the keys and then use the map() method to map the keys to the values and store the values in an array. Example: This example implements the above approach. html <body style="text-align:center;"> <h1 style="color: green"> GeeksForGeeks </h1> <h3> Alternative version for Object.values() in JavaScript. </h3> <p id="GFG_UP"> </p> <button onclick="gfg_Run()"> Click Here </button> <p id="GFG_DOWN"> </p> <script> var el_up = document.getElementById("GFG_UP"); var el_down = document.getElementById("GFG_DOWN"); var arr = []; var obj = { a: 'val_1', b: 'val_2' }; el_up.innerHTML = "Click on the button to get the values.<br>Object = " + JSON.stringify(obj); function gfg_Run() { var val = Object.keys(obj).map(function(e) { return obj[e]; }); el_down.innerHTML = JSON.stringify(val); } </script> </body> Output: Approach 2: Visit every property of the object by running a loop and push the value in an array each time. obj.hasOwnProperty() and push() method are used. Example: This example implements the above approach. html <body style="text-align:center;"> <h1 style="color: green"> GeeksForGeeks </h1> <h3> Alternative version for Object.values() in JavaScript. </h3> <p id="GFG_UP"> </p> <button onclick="gfg_Run()"> Click Here </button> <p id="GFG_DOWN"> </p> <script> var el_up = document.getElementById("GFG_UP"); var el_down = document.getElementById("GFG_DOWN"); var arr = []; var obj = { a: 'val_1', b: 'val_2' }; el_up.innerHTML = "Click on the button to get the values.<br>Object = " + JSON.stringify(obj); function getValues(obj) { var ret = []; for (var i in obj) { if (obj.hasOwnProperty(i)) { ret.push(obj[i]); } } return ret; } function gfg_Run() { el_down.innerHTML = JSON.stringify(getValues(obj)); } </script> </body> Output: Approach 3:(In ES6 format) Use the Object.keys() method to get the keys and then use the map() method to map the keys to the values and store the values in an array. Example: This example implements the above approach. html <body style="text-align:center;"> <h1 style="color: green"> GeeksForGeeks </h1> <h3> Alternative version for Object.values() in JavaScript. </h3> <p id="GFG_UP"> </p> <button onclick="gfg_Run()"> Click Here </button> <p id="GFG_DOWN"> </p> <script> var el_up = document.getElementById("GFG_UP"); var el_down = document.getElementById("GFG_DOWN"); var arr = []; var obj = { a: 'val_1', b: 'val_2' }; el_up.innerHTML = "Click on the button to get the values.<br>Object = " + JSON.stringify(obj); function gfg_Run() { el_down.innerHTML = Object.keys(obj).map(e => obj[e]); } </script> </body> Output: Comment More infoAdvertise with us Next Article Compact Objects in JavaScript P PranchalKatiyar Follow Improve Article Tags : JavaScript Web Technologies javascript-functions JavaScript-Questions Similar Reads How to invert key value in JavaScript object ? JavaScript is a high-level, interpreted, and dynamically typed client-side scripting language. JavaScript is used to add dynamic features to the static HTML. Everything is an object in JavaScript. Objects in JavaScript can be declared using figure brackets {..} and the objects may comprise certain p 2 min read How to Create Dynamic Values and Objects in JavaScript? In JavaScript, you can choose dynamic values or variable names and object names and choose to edit the variable name in the future without accessing the array, Dynamic values and objects in JavaScript allow changing, accessing, or creating values and object properties at runtime for flexibility and 3 min read Compact Objects in JavaScript Compacting an object refers to removing properties with false values (like null, undefined, 0, false, "", NaN, etc.). Objects are used to store collections of data and more complex entities. They can be extended and manipulated in various ways to suit different programming needs. One interesting asp 3 min read Different Ways to Crate an Array of Objects in JavaScript ? Objects in JavaScript are key-value pairs, making them suitable for representing structured data. Also, an array in JavaScript is a versatile data structure that can hold a collection of values. When dealing with objects, an array can be used to store multiple objects. An array of objects allows you 3 min read How to get a key in a JavaScript object by its value ? To get a key in a JavaScript object by its value means finding the key associated with a specific value in an object. Given an object with key-value pairs, you want to identify which key corresponds to a particular value, often for searching or data retrieval.How to get a key in a JavaScript object 4 min read JavaScript Object Interview Questions JavaScript objects are fundamental data structures used to store collections of data in key-value pairs. They are essential for handling more complex data and are often used in various JavaScript applications, such as APIs, web development, and data manipulation.We are going to discuss some JavaScri 9 min read Like