Created
May 1, 2015 16:14
-
-
Save stepheneyer/885e52ac5e8b09732155 to your computer and use it in GitHub Desktop.
Change from String to Array using .split(), then sort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Create a variable with a string separated by commas | |
var friends = "Moe,Larry,Curly,Jane,Emma,Elizabeth,Elinor,Mary,Darcy,Grey,Lydia,Harriet"; | |
//Create a new array of the string using the .split() method | |
//The split method needs the separator such as a comma or space ==> str.split([separator[, limit]]) | |
var newFriends = friends.split([',']); | |
console.log(newFriends); | |
//Sort the new array | |
newFriends.sort(); | |
//==> [ 'Curly', | |
'Darcy', | |
'Elinor', | |
'Elizabeth', | |
'Emma', | |
'Grey', | |
'Harriet', | |
'Jane', | |
'Larry', | |
'Lydia', | |
'Mary', | |
'Moe' ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment