Vue.js Array IndexOf
home
Run
screen_rotation
fullscreen
cloud_download
<!DOCTYPE html> <html> <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.13/vue.js"></script> </head> <body> <div id="app"> <p>item 1 = {{ item1 }}</p> <p>Element Index = {{elmnIndex}}</p> <button @click="myFunction()">Click Me</button> </div> <script> new Vue({ el: '#app', data: { item1:['12', '10', '9','5', '6', '4'], elmnIndex:'' }, methods:{ myFunction: function () { this.elmnIndex = this.item1.indexOf('9'); } } }); </script> </body> </html>
<!DOCTYPE html> <html> <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.13/vue.js"></script> </head> <body> <div id="app"> <p>item 1 = {{ item1 }}</p> <p>Element Index = {{elmnIndex}}</p> <button @click="myFunction()">Click Me</button> </div> <script> new Vue({ el: '#app', data: { item1:['12', '10', '9','5', '6', '4'], elmnIndex:'' }, methods:{ myFunction: function () { this.elmnIndex = this.item1.indexOf('9'); } } }); </script> </body> </html>
Copyrights@tutorialsplane.com