课程: JavaScript: Arrays

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Solution: Working with ordered data 1

Solution: Working with ordered data 1 - JavaScript教程

课程: JavaScript: Arrays

Solution: Working with ordered data 1

(upbeat music) - [Trainer] In this challenge, we want to sort an array of cities. So the first thing that I'm going to do is go ahead and write my return statement, and then I'm going to go ahead and type out cities, 'cause I know I'm going to be referencing that. And then for this particular example is actually going to be very straightforward. The sort method by default is going to sort alphabetically. So this would be more complicated, if we had, say, an array of objects and maybe we wanted to reference a specific property, then it gets a little bit more complicated. But in this example, we have an array of strings and we just want to sort it alphabetically, so we can simply apply the sort method to our array. So let's go ahead and check our solution and make sure we were right. And yes, of course, we've got our correct answer here. So great work on that one.

内容