screen_rotation
Copied to Clipboard
<html> <head> <script type="importmap"> { "imports": { "vue": "https://unpkg.com/vue@3/dist/vue.esm-browser.js" } } </script> <body> <div id="app"> <h3>Get the maximum value of a property in an array of objects.</h3> <button @click="getMaxValue">click me</button> <p>{{maxPrice}}</p> </div> <script type="module"> import { createApp } from "vue"; createApp({ data() { return { arrayObj: [ { fruit: 'Apple', price: 100 }, { fruit: 'Mango', price: 50 }, { fruit: 'Orange', price: 70 }, { fruit: 'Pineapple', price: 120 }, { fruit: 'Banana', price: 20 }, ], maxPrice: '' } }, methods: { getMaxValue() { this.maxPrice = Math.max(...this.arrayObj.map(property => property.price)) } } }).mount("#app"); </script> </body> </head> </html>