screen_rotation
Copied to Clipboard
<html> <head> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> </head> <body> <div id="app"> <h3>Vue Js Sorting Arrays of Objects by Numeric Property in Ascending Order</h3> <table> <tr> <th>S.no</th> <th>Developer_Name</th> </tr> <tr v-for="item in items"> <td>{{item.id}}</td> <td>{{item.name}}</td> </tr> </table><br> <button @click="sortedAsc">Sort Ascending order</button> </div> <script type="module"> const app = new Vue({ el: "#app", data() { return { items: [ { id: 102, name: 'Andrew' }, { id: 201, name: 'CodeSmith' }, { id: 3, name: 'Softwize' }, { id: 44, name: 'DevHive' }, { id: 56, name: 'Matthew Taylor' }, { id: 36, name: 'ByteBuilders' }, { id: 72, name: 'Jennifer Lee' }, { id: 88, name: 'Robert Thompson' }, { id: 91, name: 'Christopher Davis' }, { id: 150, name: 'Laura Smith' }, { id: 181, name: 'William Johnson' }, { id: 192, name: 'Elizabeth Martinez' }, { id: 134, name: 'David Lee' }, { id: 214, name: 'Andrew' }, { id: 135, name: 'AlgoAllies' }, ], } }, methods: { sortedAsc() { return this.items.sort((a, b) => { if (a.id < b.id) return -1; if (a.id > b.id) return 1; return 0; }); }, } }); </script> </body> </html>