0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JavaScriptでdeepなequals

Last updated at Posted at 2018-11-15

#Javascriptでオブジェクトの中身を比較する方法が無かった
やれJSONで比較しろだの、それはやってはいけないだのいろいろあった
のでdeepなequalsを作ってみた。

deepequals.js
function deepEquals(variable1, variable2) {
    if (typeof variable2 === "undefined") {
        return false;
    }
    if (typeof variable1 === "object") {
        $.each(variable1, function (i, e) {
            if (!deepEquals(variable1[i], variable2[i])) {
                return false;
            }
        })
    } else {
        if (variable1 !== variable2) {
            return false;
        }
    }
    return result;
}

functionとかには未対応。普通の配列とかオブジェクトであれば動作するはず。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?