Vue.js find min max element of Array
We can use JavaScript in-built math function to get the min and max value in an Array. You can use the same functions to get the min and max value from an array in vuejs.
Vue.js find min max element of Array JavaScript | VueJS Example
You cna get min and max value from an array in VueJS simply as below-
Example:
<div id="app"> <p>Array = {{ item }}</p> <p>Min Val = {{minVal}}</p> <p>Max Val = {{maxVal}}</p> <button @click="myFunction()">Click Me</button> </div> <script> new Vue({ el: '#app', data: { item:[12, 10, 9, 5, 6, 4], maxVal:'', minVal:'' }, methods:{ myFunction: function () { this.maxVal = Math.max.apply(Math, this.item); this.minVal = Math.min.apply(Math, this.item);; } } }); </script> |
Output of above example-
Advertisements