Javascript

Given a string str, create a string consisting of all the non-alphabets and non-digits.

JavaScript code

let str='q#w2@B**g';
let len=str.length;
let alpha='';
let alpha1='';
let rest='';

let digits='';
for(let i=0;i<len;i++)
{
	if(str[i]>='a'&&str[i]<='z')
	{
		alpha=alpha+str[i];

	}
    else if(str[i]>='A'&&str[i]<='Z')
	{
		alpha1=alpha1+str[i];
	}
	else if(str[i]>='0'&&str[i]<='9')
	{
		digits=digits+str[i];
	}
	else
	{
		rest=rest + str[i];
	}
}
console.log(rest);