Home > Web Front-end > JS Tutorial > body text

Examples to explain JS implementation of removing duplicate json from arrays

小云云
Release: 2017-12-22 09:28:54
Original
1681 people have browsed it

This article mainly introduces the JS method to remove duplicate json in the array, involving JavaScript traversal, judgment, access and other related operation skills for json array data. Friends in need can refer to it, hoping to help everyone better master it. Knowledge of js and json.


var array = [{"name":"123"},{"name":"123"},{"name":"456"}];
unique(array);
function unique(list) {
  var arr = [];
  for (var i = 0; i < list.length; i++) {
    if (i == 0) arr.push(list[i]);
    b = false;
    if (arr.length > 0 && i > 0) {
      for (var j = 0; j < arr.length; j++) {
        if (arr[j].typesname == list[i].typesname) {
          b = true;
          //break;
        }
      }
      if (!b) {
        arr.push(list[i]);
      }
    }
  }
  return arr;
}
Copy after login

Have you all learned it? Hurry up and give it a try.

Related recommendations:

How Vue exports json data to Excel spreadsheet method

How jquery reads data from json and appends it to In html

Manipulate JSON objects in Javascript and add a simple implementation of deletion and modification

The above is the detailed content of Examples to explain JS implementation of removing duplicate json from arrays. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!