(Disclosure: I am the owner of the linked repo)
developing/writing code block is fine and this needs deep comparision. but as a developer, we don't need to write code from scratch. we have plenty of options. We are also having a huge npm packages to get the job done specifically developed for these use case. I have used similar-js" it did the job that you need. It extends so many use cases as well.
https://www.npmjs.com/package/similar-js
npm i similar-js
import { isSimilar } from "similar-js"
const array1 = [{ a: 1 }, { b: 2 }, { c: 0, d: { e: 1, f: 2, } }, [1, 2, 3, 54]];
const array2 = [{ a: 1 }, { b: 2 }, { c: 0, d: { e: 1, f: 2, } }, [1, 2, 3, 54]];
console.log(isSimilar(array1, array2))
console.log("-------------------------------")
const collection1 = [
{ id: "1", name: "item 1", subtitle: "This is a subtitle", parentId: "1" },
{ id: "2", name: "item 2", parentId: "1" },
{ id: "3", name: "item 3", parentId: "1" },
]
const collection2 = [
{ id: "3", name: "item 3", parentId: "1" },
{ id: "2", name: "item 2", parentId: "1" },
{ id: "1", name: "item 1", subtitle: "This is a subtitle", parentId: "1" },
]
console.log(isSimilar(collection1, collection2))