Home > Web Front-end > JS Tutorial > How to remove duplicate values ​​from two arrays in js

How to remove duplicate values ​​from two arrays in js

亚连
Release: 2018-06-22 15:44:31
Original
2780 people have browsed it

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;
}
Copy after login

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 use JSONAPI in PHP

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 Using zTree tree menu

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template