How to test if two objects are the same with JavaScript?

前端 未结 5 2015
慢半拍i
慢半拍i 2021-02-15 17:35

I need a function:

function isSame(a, b){
} 

In which, if a and b are the same, it returns true.
, I tried return a === b, b

5条回答
  •  青春惊慌失措
    2021-02-15 18:02

    You could embed Underscore.js and use _.isEqual(obj1, obj2). The function works for arbitrary objects and uses whatever is the most efficient way to test the given objects for equality.

提交回复
热议问题