Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

javascript logic to accomplish getting an array of only removed image from the data received from edit product page

I have a edit product page in react using node in the backend. Look at the following scenario. A product had 4 images before (a.png, b.png, c.png, d.png). I have updated by removing the a.png image and added new image e.png. so right now I have (b.png, c.png, d.png, e.png) images available. In order to update I do not want to unlink all (a.png, b.png, c.png, d.png). as b.png, c.png, d.png is still existing. I just want to remove a.png and add d.png. By which javascript logic can I establish creating an array which will only consist of the array of image I want to remove in this case ["a.png"]

let prevImages = ['a.png', 'b.png', 'c.png','d.png']
let images = ['b.png','c.png', 'd.png', 'e.png']

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

To accomplush you wanna get is

difference = prevImages.filter(item => images.indexOf(item) < 0);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading