Front-end development: Detailed method for judging repetition of array objects

foreword

In the front-end development process, data processing is a very common operation, especially processing the data obtained from the back-end through algorithms is very important. And in front-end development, two types of data processing are necessary: ​​arrays and objects. It is not so much data processing as it is the processing of arrays and objects. In actual development, the processing of array data accounts for a higher proportion, especially when it comes to the complex hierarchical structure of form data, the processing is also very difficult. The same is true for the data processing of the combination of arrays and objects, especially the deduplication operation. There are not many methods to use directly. Front-end developers need to use algorithms to process duplicate data in the data. This article will share the actual Deduplication processing of data structures that are more commonly encountered in development: the method of judging whether there are duplicates in the front-end array object. This content is an essential skill in both actual development and front-end job interviews. Summarize it for easy reference and use.

Array object example

First, let's take a look at the data format of the array object in the front end, here is only a demonstration example, as follows:

let array = [

{id:1, name:"张三", age:30},

{id:2, name:"李四", age:24},

{id:3, name:"王五", age:36}

];

console.log(array)

 As shown in the above figure, it shows the data format and expression form of the array object.

Array object judgment duplicate

In the front-end field, there are many ways to judge whether a certain attribute in an array object is repeated. Here are mainly three ways: double-layer loop, through

Guess you like

Origin blog.csdn.net/CC1991_/article/details/132142743