JavaScript program that checks if two strings are anagrams of each other
Posted by SceDev
Last Updated: February 24, 2024

Write a JavaScript program that checks if two strings are anagrams of each other.

Code:

function checkIfAnagrams(str1, str2) {
    const formatStr = str => str.replace(/[^\w]/g, '').toLowerCase().split('').sort().join('');
    return formatStr(str1) === formatStr(str2);
  }
  
  
var result = checkIfAnagrams('Listen', 'Silent');

console.log(result);