


Removes duplicate entries from an array (there may be multiple entries), and the return value is a new array containing only the deleted duplicate entries. _javascript skills
Today I saw Taobao's online recruitment on bluediea. I believed that Taobao's technology is still very good, so I quickly opened it, took a look at the questions and tried to do it.
When I got to the third question, I was stuck for a long time. It wasn’t that I couldn’t do it. I felt that there was a very simple method but I couldn’t think of it at the moment. However, after a lot of effort, I finally completed this question and gave the answer. An answer that I am quite satisfied with, welcome your suggestions!
The question is as follows:
Please add a prototype method to the Array local object. Its purpose is to delete duplicate entries (there may be multiple) in the array entries. The return value is a value that only contains the deleted duplicates. A new array of entries.
[Ctrl A Select all Note: If you need to introduce external Js, you need to refresh to execute
The code is as follows:
Array.prototype.delRepeat=function()
{
var tmpArr=[] ,rs=[],i,val;
for(i=this.length;i>0;i--)
{
val = this[i-1];
if( !tmpArr[val])
;
this.splice(i-1, 1); Prepare this[ i-1] is stored in the variable val to reduce the number of accesses.
2. Use the array.push method to replace the method of using variables to save the length of the array.
Very good! Like it!
I also implemented the filtering of returned duplicate items, which may be due to a misunderstanding of the meaning of the question.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Article discusses creating, publishing, and maintaining JavaScript libraries, focusing on planning, development, testing, documentation, and promotion strategies.

The article discusses strategies for optimizing JavaScript performance in browsers, focusing on reducing execution time and minimizing impact on page load speed.

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

The article discusses effective JavaScript debugging using browser developer tools, focusing on setting breakpoints, using the console, and analyzing performance.

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

The article explains how to use source maps to debug minified JavaScript by mapping it back to the original code. It discusses enabling source maps, setting breakpoints, and using tools like Chrome DevTools and Webpack.

How to merge array elements with the same ID into one object in JavaScript? When processing data, we often encounter the need to have the same ID...

In-depth discussion of the root causes of the difference in console.log output. This article will analyze the differences in the output results of console.log function in a piece of code and explain the reasons behind it. �...
