Vue.Js Array Concat


We can join two or more arrays using JavaScript concat method in Vue.js. Here in this tutorial, we are going to explain how you can use this method in VueJs to join two or more arrays.


Vue.Js Array Concat Method Example

Here is an example of concat method in Vue.js-

Concat Function Example:

<div id="app">
	<p>item 1 = {{ item1 }}</p>
	<p>item 2 = {{ item2 }}</p>
	<p>Concat = {{ item3 }}</p>

	<button @click="myFunction()">Click Me</button>
</div>
<script>
 new Vue({
el: '#app',
  
  data: { 
	  item1:['a', 'b', 'c'],
	  item2:['d', 'e', 'f'],
	  item3:[]
  },
  
   methods:{
    myFunction: function () {
		
		this.item3 = this.item1.concat(this.item2);
		
    }
	}

});
</script> 

Try it »

Concat function joins two or more arrays and returns the final array.

Output of above example-

Vue.js Array concat

Advertisements

Add Comment

📖 Read More