Home  >  Article  >  Web Front-end  >  js example of removing duplicate values ​​from two arrays_javascript skills

js example of removing duplicate values ​​from two arrays_javascript skills

韦小宝
韦小宝Original
2017-12-16 14:02:421602browse

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 The example of removing duplicate values ​​from two arrays in js is all the content shared by the editor. I hope it can give you a reference, and I hope you will support the PHP Chinese website.

Related recommendations:

js to achieve simple digital change effects

Must-see js breakpoint debugging experience sharing

Native js operation dom

The above is the detailed content of js example of removing duplicate values ​​from two arrays_javascript skills. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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