Click here to Skip to main content
15,906,766 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
var personHrns:any[] = personnel?.map((item: any) => { return item.Person?.hrn ?? item.TbdRole?.hrn });
var costHrns:any[] = costshare?.map((item: any) => { return item.Person.hrn ?? item.TbdPerson?.hrn });

What I have tried:

data is like this:-
personHrns (3) ['hrn:hrs:persons:56', 'hrn:hrs:lists:FT', 'hrn:hrs:persons:171']
costHrns ['hrn:hrs:persons:56']
Updated 26-Jan-23 4:22am
Richard MacCutchan 26-Jan-23 9:51am    
You have tagged your question JavaSE6 and ReactJS; but which one is it?
Komal 99 26-Jan-23 9:57am    
Richard MacCutchan 26-Jan-23 10:05am    
Well java does not have a === comparison operator, so that code will not even compile. Looking closer at that code, that is not Java at all, it is Javascript, which is something totally different.

1 solution

The two arrays contain a different number of values, so they are clearly not equal to each other.

And even if they contained exactly the same values, Javascript only considers reference equality when applying the equality operator to arrays. Two different arrays containing exactly the same values will not be considered equal.

To properly test whether two arrays are equal, you need to test that they are the same length, and that each value is equal:
function arrayEquals(a, b) {
  return Array.isArray(a) &&
    Array.isArray(b) &&
    a.length === b.length &&
    a.every((val, index) => val === b[index]);
if (arrayEquals(costHrns, personHrns)) {

But as I said, that clearly won't work for your arrays, since they contain a different number of values.

You need to debug your code to find out why the source arrays don't contain the data you think they should contain. Nobody else can do that for you.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900