screen_rotation
Copied to Clipboard
<html> <head> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> </head> <body> <div id="app"> <h2>Vue Js Union of Two Arrays of Objects</h2> <ul> <li v-for="(item, index) in union" :key="index">{{ item.id }} - {{ item.name }}</li> </ul> </div> <script type="module"> const app = new Vue({ el: "#app", data() { return { array1: [ { id: 1, name: 'John' }, { id: 2, name: 'Mary' }, { id: 3, name: 'Tom' } ], array2: [ { id: 3, name: 'Tom' }, { id: 4, name: 'Lisa' }, { id: 5, name: 'Jane' } ], union: [] } }, mounted() { this.getUnion(); }, methods: { getUnion() { this.union = this.array1.concat(this.array2).filter((item, index, self) => { return index === self.findIndex((t) => ( t.id === item.id && t.name === item.name )); }); } } }) </script> </body> </html>