Vue.js Array findIndex
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>Result = {{ 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.findIndex(this.checkNum); }, checkNum:function(num){ if(num < 9){ return num; } } } }); </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>Result = {{ 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.findIndex(this.checkNum); }, checkNum:function(num){ if(num < 9){ return num; } } } }); </script> </body> </html>
Copyrights@tutorialsplane.com