Home >Web Front-end >JS Tutorial >How to remove duplicate values from two arrays in js
The editor below will share with you an example of removing duplicate values from two js arrays. It has a good reference value and I hope it will be helpful to everyone. Let’s follow the editor and take a look.
The examples are as follows:
//两数组去除重复数值 mergeArray: function(arr1, arr2) { for (var i = 0; i < arr1.length; i++) { for (var j = 0; j < arr2.length; j++) { if (arr1[i] === arr2[j]) { arr1.splice(i, 1); //利用splice函数删除元素,从第i个位置,截取长度为1的元素 } } } //alert(arr1.length) for (var i = 0; i < arr2.length; i++) { arr1.push(arr2[i]); } return arr1; }
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future. help.
Related articles:
How to implement animated checkboxes in anime.js
How to solve tap in fastclick code "Point through"
The problem that beforeRouteLeave cannot be triggered when the browser goes back when using Vue
How to do it in Parcel.js Vue 2.x To extremely fast zero-configuration packaging
How to implement recording and playback recording functions in WeChat applet
How to use navigation guard usage in VueRouter
How to implement table paging in vue element
How to implement a collapsible tree menu in Vue.js
About webpack3 speedup in vue-cli Optimization issues
The above is the detailed content of How to remove duplicate values from two arrays in js. For more information, please follow other related articles on the PHP Chinese website!