I have two JavaScript arrays (A
and B
) that contain objects that I created. I want to check that all the objects in array A
are contained in array B
, but not necessarily in the same order.
What is the best way to do this?
Edit:
They are all actual objects, not primitives, so I will need to compare their contents and structure as well (maybe using something like JSON.stringify
).
I want to do this because I'm learning Test-Driven Development, and I want to test functions that return lists of objects. I need to test whether the returned lists have the expected objects in them or not (order doesn't matter in this case).
true
,false
,23
or actual objects? Also can you explain why you want to do this? There may be a better way. – Hedonics