I have the following two strings:
var str1 = \"hello\";
var str2 = \"ehlol\";
How can I check whether both strings contain the same characters?
You can use a function for this purpose like sameChars
function here-
function myFunction()
{
var input_1 = document.getElementById('input_1').value;
var input_2 = document.getElementById('input_2').value;
var result = sameChars(input_1,input_2);
document.getElementById("demo").innerHTML = result;
}
function sameChars(firstStr, secondStr)
{
var first = firstStr.split('').sort().join('');
var second = secondStr.split('').sort().join('');
return first.localeCompare(second)==0;
}