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>Sorting the Array in Descending Order and Displaying the Result on click</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="sortedDes">Sort Desending 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: { sortedDes() { return this.items.sort((a, b) => { if (b.id < a.id) return -1; if (b.id > a.id) return 1; return 0; }); }, } }); </script> </body> </html>