To determine whether to use a for…in loop or Object.values, consider a scenario with two objects const Product = { name:”product1″, price:100, } const ProductInvoice = { invoiceno : “invoice1”, customer : “customer1”, } These objects are linked to each other in the prototype chain. Object.setPrototypeOf(ProductInvoice, Product); Now, you iterate and list the values withContinueContinue reading “Choosing Between for..in Loops and Object.values() in JavaScript”
Tag Archives: object.values
Object.values to iterate JavaScript object properties
In JavaScript, you can display the values of all public enumerable properties of an object by using Object.values(). For instance, if you have an object like the one depicted below: const Product = { name:”p1″, price:100, } You can output the values of all properties by utilizing Object.values() like this: let p = Object.values(Product); console.log(p);ContinueContinue reading “Object.values to iterate JavaScript object properties”