javascript how to sort strings containing comma separated values

I would like to know how can I sort strings in javascript containing comma separated values in different order e.g.

    var str1 ="aaa,SC,AAA,mc,mc,aaa";
    var str2 ="AAA,SC,aaa,aaa,mc,mc";

So basically i want to sort them and do an equality comparion check.

    if(str1==str2)
    // do something...

Your help will be appreciated.

Thanks

Answers


str.split(",").sort().join(",")

Need Your Help

How do i load data Infile in multiple tables?

mysql insert bulkinsert

hi i run python program where im inserting many many new entries to database,

Get an array of the bit positions within a 64-bit integer

c++ c 64bit bit-manipulation bits

OK, it may sound a bit complicated, but this is what I'm trying to do :

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.