Vue.Js Array Map
This method created a new array by calling a function for each element. Here in this tutorial, we are going to explain how to use JavaScript Array Map function in vue.js. You can use our online editor to edit and run the code online.
Vue.Js Array Map Method Example
You can use Array Map function in vue.js simply as below-
Example:
<div id="app"> <p>item 1 = {{ item1 }}</p> <p><input type="text" v-model="myModel" placeholder="Enter Number"></p> <p>Result = {{result}}</p> <button @click="myFunction()">Click Me</button> </div> <script> new Vue({ el: '#app', data: { item1:[12, 10, 9, 5, 6, 4], result:'', myModel:2 }, methods:{ myFunction: function () { this.result = this.item1.map(this.testFunction); }, testFunction: function(num) { return num*this.myModel; } } }); </script> |
Output of above example-
Advertisements