Find matching values in two arrays
You can use the combination of map
and includes
helper to achieve that.
let firstArray = ["One", "Two", "Three", "Four", "Five"];
let secondArray = ["Three", "Four"];
let jsonArray = [];
jsonArray = firstArray.map(i => {
return { 'name': i, 'matched': secondArray.includes(i) };
});
console.log(jsonArray);
Filtering two arrays for matching values into new array in Javascript
const newArr = strArr2.filter(value => strArr1.includes(value) && arr.splice(arr.indexOf(value), 1));
This works :)
finding matching value in two arrays or lists using loop
res = [key for key, val in enumerate(data) if val in data1]
print(res)
Output:
[1, 2, 4, 5]
Javascript compare 2 arrays of objects find matching values and make change
It seems your regex is removing the email address from the from
property, rather than preserving it. Here's a sample with a different regex that pulls out the email during comparison and ignores the rest.
const nickNames = [
{
nickName:"Dad",
emailAddress:"dad@dad.com",
},
{
nickName:"Mom",
emailAddress:"mom@mom.com",
},
{
nickName:"BFF",
emailAddress:"bff@bff.com",
}
]
let emails = [
{
from:"Dad Dadson <dad@dad.com>"
},
{
from:"Mom Dadson <mom@mom.com>"
},
{
from:"Brother Dadson <bro@bro.com>"
}
]
emails.forEach(email => {
const match = nickNames.find(nickName => nickName.emailAddress === email.from.replace(/^(.* )<(.+)>$/, "$2"));
if (match) {
email.nickName = match.nickName;
}
});
console.log(emails);
finding matching values in two arrays
for (var lo = 0; lo < LocalJSONObject.length; ++lo) {
for (var va = 0; va < value.length; ++va) {
if (value[va] === LocalJSONObject[lo].value) {
console.log('Matching values:', value[va]);
}
}
}
Related Topics
React Button Onclick Redirect Page
How to Partition Input Field to Appear as Separate Input Fields on Screen
How to Wait for One Function to Finish Before Continuing
Check If Json Response Data Is Empty
How to Get Full Path of Selected File on Change of <Input Type='File'> Using Javascript, Jquery-Ajax
Regex to Find Json Values Without Quotes
Jquery Ajax Post Results in 500 Internal Server Error
Javascript - Auto Click on a Button on Page Load
Jquery Validation Code for Not Allowed Only Blank Space in Textbox
How to Loop Through Json Array and Get Specific Values
Print Function Not Working in Chrome
How to Save .Xlsx Data to File as a Blob
How to Output a Pdf Buffer to Browser Using Nodejs
Hide Menu Sidebar When Clicking Outside the Bar or the Button
React | How to Detect Page Refresh (F5)
How to Uncheck All Below Checkboxes When One Checkbox Is Unchecked