Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

139
Views
JavaScript: managing two separate arrays, ant design transfer component

Consider two arrays leftArray (data is local) and rightArray (data is inside server).

So my component allows users to swap elements inside the list with each other, either upload to the server or remove from server using the left and right buttons.

The left button is to remove the elements from the server and The right button is to send elements to the server.

Please refer the image below, This is what Ant design Transfer component looks like:

Ant Design Transfer Component

So my issue is when user manipulates the data, either to the left of right, I want to have all the keys which which are newly added or removed from the server. But the elements on the rightArray which is already in the server, I do not need the keys, because it is already in the server.

So how would I separate the assigned keys (right list) and unassigned keys (left list)? The function onChange runs whenever the user either clicks left or right, I initially declare two empty arrays and start concatenating, either addList or removeList, Now I want to find out exactly which keys are removed from the server and which keys are added from the server.

below is the function onChange:

if (direction === 'right') {

 addedList= addedList.concat(movedKeysRight)
 addedList= [...new Set(addedList)] // to remove duplicate elements Incase a list 
 item is added to the right, removed and then added again I don't want to repeat the keys 
 that's why I have it here
}
if (direction === 'left') {
  removedList = removedList.concat(movedKeysLeft)
  removedList= [...new Set(removedList)]
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!