58
Simple and Quick Array Comparison
2021-04-14 - JavaScript
1// JS Tip of the Day
2// Simple and Quick Array Comparison
3
4const arrayComparison = (firstArray, secondArray) => {
5 return JSON.stringify(firstArray) === JSON.stringify(secondArray);
6}
7
8const heroes = ['Batman', 'Superman', 'Green Arrow'];
9const moreHeroes = ['Batman', 'Superman', 'Green Arrow'];
10
11arrayComparison(heroes, moreHeroes); // true
12/*
13 Attention!
14 It falls with different values serialized but
15 with the same string conversion like null, undefined, ...
16*/
#JStipoftheday