Program to check if given two strings are anagram in Javascript


Below program is to check the given two strings are anagram or not in Javascript

let str1 ="care";
let str2="race";

let sortedStr1=str1.split('').sort().join();
let sortedStr2=str2.split('').sort().join();

if (sortedStr1===sortedStr2){
  console.log("Given strings are anagram");
} else {
  console.log("Given strings are not anagram")
}

Try yourself by executing above code https://onecompiler.com/javascript/3xmh279va