JavaScript Array Sort Method Practice in 5 Minutes

Learn to use the Sort() function to customize how an array is sorted.
Arrays are an essential part of JavaScript. If you want to get better at JavaScript, you have to know how to effectively use arrays, especially the built-in array methods like map, reduce, filter, sort, every, some, etc. In this series, we'll cover the JavaScript array methods you need to know to become a web developer.
Array Worksheet - bit.ly/jqq-array-practice
Join the 💬 Discord Server 💬 - / discord
_____________________________________________
Newsletter 🗞
Interested in exclusive content and discounts? 🤯 Sign up for the newsletter!
www.jamesqquick.com
_____________________________________________
Connect with me 😀
Live streams on Twitch - / jamesqquick
Follow me on Twitter - / jamesqquick
Join the 💬 Discord Server 💬 - / discord
_____________________________________________
COURSES 💻
Learn how to build Fullstack apps with React and Serverless Functions - www.jamesqquick.com/courses/r...
Learn everything you need to know about Visual Studio Code - www.udemy.com/learn-visual-st...
Build a Quiz App - www.udemy.com/build-a-quiz-ap...

Пікірлер: 55

  • @aaronlinton-chambers
    @aaronlinton-chambers3 жыл бұрын

    This is by far my favourite coding channel on KZread. Clear concise instructions and a worksheet to engage with. Thanks James have an amazing Thursday.

  • @JamesQQuick

    @JamesQQuick

    3 жыл бұрын

    Wow that’s like the best compliment I’ve ever gotten! :)

  • @nicholaskozlarek3169
    @nicholaskozlarek3169 Жыл бұрын

    This repository was amazing. I am starting a coding bootcamp in a few days and brushing up on this makes me feel WAAAAY more confident. Thanks!

  • @KieCodes
    @KieCodes3 жыл бұрын

    Again an amazing value packed video! Thank you!

  • @bradpeters9511
    @bradpeters95112 жыл бұрын

    Very easy to understand. Thank you for doing examples with numbers and strings.

  • @TheMugen18
    @TheMugen182 жыл бұрын

    Thank you James! Very cool and understandable tutorials !

  • @PFOctavio
    @PFOctavio3 жыл бұрын

    All this videos have helped me so much, i really appreciate them

  • @mariapaderina5992
    @mariapaderina59923 жыл бұрын

    Thank you James! Very cool and understandable tutorials ! I got the idea of array` s methods only from your videos!

  • @stefanzander5956
    @stefanzander59563 жыл бұрын

    Didactically very well produced and presented. Great Work!

  • @exodion4173
    @exodion4173 Жыл бұрын

    I loved that there were different types of examples. Thank you

  • @mihirrawat3074
    @mihirrawat30743 жыл бұрын

    Keep doing what u do, great mann!

  • @jazper808
    @jazper8082 жыл бұрын

    thank you James for sharing knowledge.

  • @FPLogistic
    @FPLogistic2 жыл бұрын

    I finally understand it, thank you!

  • @luciamelgarejo2953
    @luciamelgarejo2953 Жыл бұрын

    Thank you. You teach amazing!.

  • @anahitharutyunyan3066
    @anahitharutyunyan3066 Жыл бұрын

    Thank you for great explanation.

  • @elie8181
    @elie81813 жыл бұрын

    Hello James, thanks and very good job, from France !

  • @gbbowler
    @gbbowler3 жыл бұрын

    James, these are great short vids. I love doing the short exercises.

  • @JamesQQuick

    @JamesQQuick

    3 жыл бұрын

    Glad you’re enjoying it. Any other topics you’d like to see?

  • @zacwilson8009
    @zacwilson80093 жыл бұрын

    I love how you have the repo for these lessons. Keep it up man you're killing it

  • @JamesQQuick

    @JamesQQuick

    3 жыл бұрын

    Yaaaaa! :)

  • @mohamedyoussef8835
    @mohamedyoussef88352 жыл бұрын

    Excellent

  • @jeka2233
    @jeka22332 жыл бұрын

    So helpful

  • @arjmli
    @arjmli Жыл бұрын

    Thank you

  • @fenrirbr
    @fenrirbr3 жыл бұрын

    small suggestion, you could've used a console.clear() at the start of the file so following the console would be a little clearer

  • @JamesQQuick

    @JamesQQuick

    3 жыл бұрын

    That’s a great idea!

  • @doniaelfouly4142
    @doniaelfouly4142 Жыл бұрын

    Thanks

  • @ind_gagan1
    @ind_gagan13 жыл бұрын

    Wow...Javascript series ❤❤ Really excited for this series

  • @JamesQQuick

    @JamesQQuick

    3 жыл бұрын

    Hope you’re enjoying it so far!

  • @ind_gagan1

    @ind_gagan1

    3 жыл бұрын

    @@JamesQQuick you are someone who is helping young developers a lot....big thanks to you...im currently learning frontend web development and its so amazing and your videos are huge support for us. Thankyou so much James ❤😀

  • @JamesQQuick

    @JamesQQuick

    3 жыл бұрын

    @@ind_gagan1 This means a lot! :) Thank you!!

  • @maxlong1374
    @maxlong1374 Жыл бұрын

    Better than GOT for an eager heart to learn

  • @Alphadec
    @Alphadec3 жыл бұрын

    how do u display each object in a card. ?

  • @reanibutani9555
    @reanibutani95553 жыл бұрын

    I want to be great at javascript :)

  • @RClips123
    @RClips123 Жыл бұрын

    how do i get the terminal to work

  • @Singlerity
    @Singlerity2 жыл бұрын

    New to coding here. I don't understand how sort by name works. How does the conditional understand that Anakin is alphabetically smaller than Darth? Do the strings have hidden alphabetical values?

  • @JamesQQuick

    @JamesQQuick

    2 жыл бұрын

    Great question. They have hidden mathematical values actually. Each character has a number code behind it so they can be sorted mathematically.

  • @vladrileynavilys

    @vladrileynavilys

    2 жыл бұрын

    @@JamesQQuick "character" being, in this case the letters forming each character's name!

  • @panoptech769
    @panoptech769 Жыл бұрын

    what are you saying you are running at 2:25? Did you say node mod? trying to get that extension but cant find it

  • @Hacking-NASSA-with-HTML

    @Hacking-NASSA-with-HTML

    Жыл бұрын

    I believe it's a Nodemon, live updating your js file; something like "live server" extension for VSCode editor which works with html files (I use it)

  • @Hacking-NASSA-with-HTML

    @Hacking-NASSA-with-HTML

    Жыл бұрын

    I mean you just create a blank index HTML file, put a script file inside HTML, and start live server. Works perfectly.

  • @jonathansigg8563
    @jonathansigg85633 жыл бұрын

    instead of doing return twice, you should better use this ------> const byName = characters.sort((a, b) => a.name < b.name ? -1 : 1);

  • @Ashish_singh_dev
    @Ashish_singh_dev3 жыл бұрын

    those who are looking for james's github page which he might forgot to put in his video's description data page link :- github.com/jamesqquick/javascript-array-functions-practice

  • @mithunshaw4269
    @mithunshaw4269 Жыл бұрын

    how to sort each words in an array like was would be aws, and would be adn and so on... first we sort entire array and then how do we sort each words and print them like below //input let str = 'ram ramesh sahil harsh abhay ali gopi' // output -> 'aabhy aehmrs ahhrs ahils ail amr giop'

  • @soniablanche5672
    @soniablanche56723 жыл бұрын

    btw .sort() does not return a new array, it returns the original for convenience.

  • @kennyPAGC
    @kennyPAGC3 жыл бұрын

    You need to return 0 when the sort value is the same. I guess returning nothing works the same way (undefined), but the docs are explicit about returnin 0, so that's how it should be done if you want to do it "properly".

  • @JamesQQuick

    @JamesQQuick

    3 жыл бұрын

    Fair enough. Ya it doesn’t really matter what you return but always good to reference the docs.

  • @soniablanche5672

    @soniablanche5672

    3 жыл бұрын

    In his examples, he either returning 1 or -1. He never returned undefined.

  • @micemincer
    @micemincer3 жыл бұрын

    isn't anakin and darth vader the same character?

  • @mapkbalaji
    @mapkbalaji3 жыл бұрын

    What to do if we need to sort by gender and name?

  • @vmag77

    @vmag77

    3 жыл бұрын

    This is how i did it, but i'm sure there is probably a better way. const byGender = characters.sort((a, b) => { if (a.gender if (a.gender > b.gender) return 1; if (a.name if (a.name > b.name) return 1; }); console.log('----- Sorted by Gender -----'); console.log(byGender);

  • @soniablanche5672

    @soniablanche5672

    3 жыл бұрын

    Assuming you want to create a general comparator function, you can do something like this. Keep in mind that it will compare the properties directly so you'd have to modify the logic of comparison to suit your needs: function comparator(...properties) { return function(a,b) { const property = properties[0]; if(a[property] > b[property]) return -1; if(a[property] if(properties.length > 1) return comparator(...properties.slice(1))(a,b); return 0; } } characters.sort(comparator("gender","name")); this should sort by gender, and if gender is equal then it will compare the names. You can keep adding parameters to the comparator function if you want to sort by even more properties.

  • @TomS-rv8me

    @TomS-rv8me

    2 жыл бұрын

    This also works: const sortGenderName = characters.sort((a,b) => `${a.gender}${a.name}` > `${b.gender}${b.name}` ? 1 : -1); console.log(sortGenderName); For anything more complicated, the function approach described above would probably be better.

  • @thomasersosi4595
    @thomasersosi45953 жыл бұрын

    Take a look at developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare for sorting strings.

  • @vikrantshah1633
    @vikrantshah16332 жыл бұрын

    What about Dates it’s confusing

  • @DastageerHC
    @DastageerHC2 жыл бұрын

    you did everything except explaining how the sort method works