English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
This article illustrates a method to remove duplicate JSON objects from an array in JavaScript. Shared for everyone's reference, the details are as follows:
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; }
PS: Regarding json operations, here are several practical online json tools recommended for everyone's reference and use:
onlineJSON code check, check, beautify, format tool:
http://tools.jb51.net/code/json
JSONOnline formatting tool:
http://tools.jb51.net/code/jsonformat
online XML/JSON conversion tool:
http://tools.jb51.net/code/xmljson
jsoncode online formatting/beautify/compress/edit/Conversion Tool:
http://tools.jb51.net/code/jsoncodeformat
onlinejson compression/Escape Tool:
http://tools.jb51.net/code/json_yasuo_trans
More about JavaScript related content can be viewed in the special topics of this site: 'Summary of json operation skills in JavaScript', 'Summary of search algorithm skills in JavaScript', 'Summary of error and debugging skills in JavaScript', 'Summary of data structure and algorithm skills in JavaScript', 'Summary of traversal algorithm and skills in JavaScript', and 'Summary of mathematical operation usage in JavaScript'.
I hope the content described in this article will be helpful to everyone in programming JavaScript.
Declaration: The content of this article is from the Internet, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been manually edited, and does not assume relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#oldtoolbag.com (When reporting, please replace # with @ and provide relevant evidence. Once verified, this site will immediately delete the infringing content.)