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?

【JavaScript】配列同士を中身で比較する

0
Posted at

結論

  • JavaScript では、配列は中身ではなく、同じ配列オブジェクトを参照しているかで比較される
  • 中身で同一かどうか比較したい場合はシリアライズして文字列として比較

詳細

ex.js
const a = ['OS', 'Compiler'];
const b = ['OS', 'Compiler'];

return a === b;

→falseが返る

const a = ['OS', 'Compiler'];
const b = ['OS', 'Compiler'];

return JSON.stringfy(a) === JSON.stringfy(b);

→trueが返る

その他配列比較方法

image.png

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?