Javascript Deep Comparison

后端 未结 3 447
感动是毒
感动是毒 2021-01-21 05:35

Questions about deep comparison of objects have been asked, and I have the solution. But there is a line in the solution that I don\'t completely understand.

This is the

3条回答
  •  滥情空心
    2021-01-21 06:00

    According to MDN:

    The in operator returns true if the specified property is in the specified object.

    Also:

    The for...in statement iterates over the enumerable properties of an object, in arbitrary order. For each distinct property, statements can be executed.

    So to answer your first question, prop in a is checking whether prop, a field from object b, exists in object a.

    To answer your second question, deepEqual(a[prop], b[prop]) is checking whether the object a[prop] and b[prop] are equal including all its children and contents.

提交回复
热议问题