How to sort objects in Javascript using array,sort #shorts

preview_player
Показать описание

My VSCode Extensions:
- theme: material community high contrast
- fonts: Menlo, Monaco, 'Courier New', monospace
- errors: Error Lens
- extra git help: Git Lens
- tailwind css intellisense
- indent rainbow
- material icon theme
- prettier & eslint
- ES7+ React Snippets
Рекомендации по теме
Комментарии
Автор

You are easily the best YouTuber using shorts in my feed. Love it. ❤

hugodsa
Автор

Names.sort((a, b)=>b.isPaid - a.isPaid);
Shorter Code 😉

hamzadarej
Автор

With type coercion, you can return the subtraction of their isPaid properties.

Pacvalham
Автор

What extension are you using to show errors like that ?

arditzubaku
Автор

i would do: names.sort((a, b) => b.isPaid - a.isPaid)

IdleAtre
Автор

What screen recording app are you using? Great videos

sagirorlich
Автор

if we are using is "is" prefix for Booleans, that name attribute could use a "str" prefix. Actually I wish there was a way to declare types in javascript... Oh wait!

sayamqazi
Автор

Good practice: always use a [...spread operator] when sorting an array so you don't accidentally mutate your original array

yadusolparterre
Автор

is it bcoz of any kind of extension he uses which helps him to show errors as you type ?

sahadpop
Автор

Is this similar to comparator in Java?

davidriveramorales
Автор

I'd love a video about functioning programming approaches / advanced functions

kristiyanbalevski
Автор

I'd love your opinion on this, do you think it's important to stick with if statements when writing something like this?

For example, you can accomplish the same thing using this:

arr.sort((a) => (a.isPaid == true) ? -1 : 1);

Because the property is binary, it must either be true or not true I simplified it to make it the most readable it can be.. but I have to wonder do you think it's a better practice to avoid ternary operators for readability? Obviously, for more complex logic this readability doesn't scale, but it's nice to get opinions from people who have worked with JS longer.

explodatedfaces