How to use Object.values() In Javascript
By using the Object.values(obj) method, we will get an array of values, which we will further use for extracting the data. We have defined a function that retrieves the values by using an index using the method Object.values().
Example : Let’s see an example to demonstrate the above
Javascript
let obj = { a: "abc" , b: "cde" , findByIndex: function (n) { let arr = Object.values( this ) return arr[n] } }; console.log(obj.findByIndex(0)) |
Output
abc
JavaScript Program to Access Non-Numeric Object Properties by Index
In JavaScript, we can access non-numeric object properties by their keys (property names) rather than by index, as objects are not indexed like arrays. Objects use key-value pairs to store data. But there are certain ways to achieve this using the properties of the objects.