Deduplication of objects in an array

An array with objects inside, like:

{"key","v1"}

{"key","v2"}

{"key","v3"}

When continuing to add to the array in the future, it is required that the value is not repeated

You can create another array newArr in the following form, which only contains value

Then you can repeatedly interpret the value of newArr through JQuery:

$.inArray(“value”,newArr)<0

This method, if the value exists, returns the subscript where it is located, otherwise returns -1

 

In this way, the repeated judgment of the objects in the array is avoided by changing the space for time.

It can also use the encapsulation method of JQuery to improve efficiency

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326486832&siteId=291194637