Learn how to use lodash to extract the differing values between an array of values and an array of objects

I have two arrays:

a1 = ['<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f480918780c5b49399959d98da979b99">[email protected]</a>','<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="493d2c3a3d7b092e24282025672a2624">[email protected]</a>','<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b5c1d0c6c186f5d2d8d4dcd99bd6dad8">[email protected]</a>'];
a2 = [{email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ed99889e99dcad8a808c84881c38e8280">[email protected]</a>'},{email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="750110060147351218141c195b161a18">[email protected]</a>'}];

I would like to find the difference between the two arrays, resulting in:

resultDifference = ['<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="37435244430477505a565e5b1954585a">[email protected]</a>'];

To achieve this using only lodash, how can I proceed?

Answer №1

Make sure to include the steps you have already taken in your post

const emails1 = ["<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="37435244430677505a565e5b1954585a">[email protected]</a>", "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7a0e1f090e483a1d171b131654191517">[email protected]</a>", "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b3c7d6c0c780f3d4ded2dadf9dd0dcde">[email protected]</a>"];
const emails2 = [{ email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="31455442450071565c50585d1f525e5c">[email protected]</a>" }, { email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1a6e7f696e285a7d777b737634797577">[email protected]</a>" }];

const differentEmails = _.difference(
  emails1,
  emails2.map((item) => item.email)
);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Validating Floating Point Numbers in C++

Hey there, I have a float array that only stores 1s and 0s. I'm attempting to run a simple test where if the current index in the array is 1, it will display a message saying it is 1, otherwise it will say it's 0. Here's my code snippet: if ...

Acquire a structured list of the focus order within the DOM elements

It intrigues me how the DOM is constantly changing. I'm curious if there's an easy way to retrieve a sorted list of focusable elements within the DOM at any moment. This would encompass nodes with a specified tabindex value that isn't -1, as ...

Discover the secrets to activating Next.js's 12-factor application bundling capabilities!

Exploring the Next.js documentation on environment variables - To ensure the security of server-only secrets, Next.js substitutes process.env.* with the correct values during build time. Does this imply that only the environment variables set at build t ...

Netbeans Error: Application crashing during runtime with 2D dynamic array

I have a task to create a 2D dynamic array with a size equal to M*M (user input), where both the column and row are of the same size M. The issue I'm facing is that after entering values for M and K, the application crashes. I am struggling to grasp ...

Retrieve all data with the same attribute name in one statement from the ajax call

After making an Ajax call, I receive the following data, which includes two images but the number of images can vary: [{"BadgeImage":"http:\/\/localhost:8666\/web1\/profile\/images\/badge image 2\/1.png"}, {"BadgeImag ...

What are some effective strategies for developing an API that has a prolonged response time?

While working on an API endpoint that requires calling multiple external services/DBs, I want to ensure that my users do not face delays in the process. However, the outcome of this process is crucial for their experience. My initial idea is to enqueue th ...

Calculating the total of fields from populated documents using Mongoose

In my application, I have two main models: User and Track. A User can complete various Tracks and earn points for each one. The schema for the User model looks like this: let userSchema = new mongoose.Schema({ name: {type: String, required: true}, ...

Creating an array by combining two queries using loops: What's the best approach?

I am trying to set the primary array to have the property of a foreign key I have two tables, tipe_akademik and jam_akademik_a The jam_akademik table has a foreign key pointing to tipe_akademik My goal is to display tipe_akademik as having a list of jam ...

How to use ajax() to return multiple arrays successfully in jQuery

Hey everyone, I'm working on an AJAX function in jQuery that parses an XML file, creates an array on success, and wants to return multiple arrays on callback. Is it possible? If so, how can I achieve this? Please guide me through this. var arr1 = new ...

Integrating JSON back into the system

As I work with Axios to retrieve information from an API, I am able to successfully connect and receive an object with the necessary data. However, I am struggling to display this JSON data in my HTML code. Here is the code snippet I am using: <body&g ...

Issue with custom fonts not showing in PDFs when using Puppeteer, even though they are displayed in screenshots

I've been working on dynamically creating PDF files using the puppeteer library, but I'm facing an issue where the generated PDF doesn't display the custom fonts (.woff) that I have specified. Instead, it defaults to using the system font, T ...

Ways to generate data following the integration of Firebase Firestore in Vue.JS

How can I display the orders data retrieved from Firebase in my browser console? See the image link below for reference. https://i.sstatic.net/HPlaC.png This is the code snippet for fetching data from Firebase and displaying it in the console: orders(){ ...

Angular's ngSubmit is malfunctioning

Check out this code snippet: <form data-ng-submit="ctrl.filter()" novalidate="true" class="search-filter ng-valid ng-dirty ng-valid-parse"> <fieldset> <div class="search-filter-group"> <div class="s ...

Issue: Proper handling of data serialization from getStaticProps in Next.js

I've been working on Next.js and encountered an issue while trying to access data. Error: Error serializing `.profileData` returned from `getStaticProps` in "/profile/[slug]". Reason: `undefined` cannot be serialized as JSON. Please use `nul ...

Trigger an event upon completion of the angular $route.reload() function

I am encountering an issue where I need to refresh the route using the following code: $route.reload(); However, I also need to trigger a function just before the template is rendered again. For instance: $("#someTab").click(); Your help would be grea ...

Encountered a React error stating: `TypeError: this.state.projects.map is not a

export default class Timeline extends Component{ state = { projects : [], }; async componentDidMount(){ const response = await api.get("/projects"); this.setState({projects: response.data}); } render(){ return ( <div className ...

Encountered a problem while attempting to convert column chart to 3D using Google Sheets API

I've encountered a problem while attempting to convert all column charts in my spreadsheet to 3D column charts. Despite following Google's documentation, I receive an error message when running the code below. Could this be an issue with the API ...

Pulling the month name based on a specific year and week using Javascript

In my HTML form, there are two fields called Year and Week. When the user chooses a Year and Week from the dropdowns, I would like to show the corresponding Month Name for that specific year and week. Is there anyone who can assist me in retrieving the m ...

Overflow-y SweetAlert Icon

Struggling with a website modification issue where using Swal.fire(...) causes an overflow problem affecting the icon rendering. How can this be fixed? Here is the custom CSS code in question: * { margin: 0px; padding: 0px; font-family: &ap ...

Unexpected obstacles encountered when implementing the jqTouch JavaScript/AJAX combination on Android

In jqtouch, I'm using vanilla ajax calls to load multiple pages: <li class="arrow"><a href="folder/another/somepage.html" >BRAVIA HDTVs</a><small class="counter">2</small></li></li> I want to incorporate a v ...