I have an array of object containing a status and a name property.
I want to use them based on their name property using the following code:
array = array.sort(function(a,b){
   return a.name - b.name
});
However it doesn't return the correct sorted array. Here is a snippet so you can see it in action:
var array = [{"name":"whoopsie","status":"active"},{"name":"acpid","status":"active"},{"name":"apache2","status":"active"},{"name":"apparmor","status":"active"},{"name":"apport","status":"active"},{"name":"avahi-daemon","status":"active"},{"name":"bluetooth","status":"active"},{"name":"cron","status":"active"},{"name":"cups","status":"active"},{"name":"cups-browsed","status":"active"},{"name":"dbus","status":"active"},{"name":"grub-common","status":"active"},{"name":"irqbalance","status":"active"},{"name":"kmod","status":"active"},{"name":"lightdm","status":"active"},{"name":"lvm2-lvmetad","status":"active"},{"name":"lvm2-lvmpolld","status":"active"},{"name":"apache-htcacheclean","status":"active"},{"name":"network-manager","status":"active"},{"name":"networking","status":"active"},{"name":"postfix","status":"active"},{"name":"procps","status":"active"},{"name":"resolvconf","status":"active"},{"name":"rsyslog","status":"active"},{"name":"smartmontools","status":"active"},{"name":"smbd","status":"active"},{"name":"speech-dispatcher","status":"active"},{"name":"ssh","status":"active"},{"name":"thermald","status":"active"},{"name":"tlp","status":"active"},{"name":"udev","status":"active"},{"name":"ufw","status":"active"},{"name":"lvm2-lvmpolld","status":"inactive"},{"name":"mysql","status":"active"},{"name":"alsa-utils","status":"inactive"},{"name":"x11-common","status":"inactive"},{"name":"apache-htcacheclean","status":"inactive"},{"name":"avahi-daemon","status":"inactive"},{"name":"console-setup.sh","status":"inactive"},{"name":"cryptdisks","status":"inactive"},{"name":"cryptdisks-early","status":"inactive"},{"name":"cups-browsed","status":"inactive"},{"name":"grub-common","status":"inactive"},{"name":"hwclock.sh","status":"inactive"},{"name":"kerneloops","status":"inactive"},{"name":"keyboard-setup.sh","status":"inactive"},{"name":"laptop-mode","status":"inactive"},{"name":"lvm2","status":"inactive"},{"name":"lvm2-lvmetad","status":"inactive"},{"name":"anacron","status":"inactive"},{"name":"network-manager","status":"inactive"},{"name":"nmbd","status":"inactive"},{"name":"plymouth","status":"inactive"},{"name":"plymouth-log","status":"inactive"},{"name":"pppd-dns","status":"inactive"},{"name":"prometheus","status":"inactive"},{"name":"rsync","status":"inactive"},{"name":"samba","status":"inactive"},{"name":"samba-ad-dc","status":"inactive"},{"name":"saned","status":"inactive"},{"name":"speech-dispatcher","status":"inactive"},{"name":"unattended-upgrades","status":"inactive"},{"name":"uuidd","status":"inactive"},{"name":"unattended-upgrades","status":"active"}];
array = array.sort(function (a,b) {
    return a.name - b.name
})
console.log(array.map(function(i){
    return i.name
}))I am running this code in nodejs
[ 'whoopsie',
  'unattended-upgrades',
  'apache2',
  'apparmor',
  'apport',
  'avahi-daemon',
  'bluetooth',
  'cron',
  'cups',
  'cups-browsed',
  'dbus',
  'grub-common',
  'irqbalance',
  'kmod',
  'lightdm',
  'lvm2-lvmetad',
  'lvm2-lvmpolld',
  'apache-htcacheclean',
  'network-manager',
  'networking',
  'postfix',
  'procps',
  'resolvconf',
  'rsyslog',
  'smartmontools',
  'smbd',
  'speech-dispatcher',
  'ssh',
  'thermald',
  'tlp',
  'udev',
  'ufw',
  'acpid',
  'mysql',
  'alsa-utils',
  'x11-common',
  'apache-htcacheclean',
  'avahi-daemon',
  'console-setup.sh',
  'cryptdisks',
  'cryptdisks-early',
  'cups-browsed',
  'grub-common',
  'hwclock.sh',
  'kerneloops',
  'keyboard-setup.sh',
  'laptop-mode',
  'lvm2',
  'lvm2-lvmetad',
  'anacron',
  'network-manager',
  'nmbd',
  'plymouth',
  'plymouth-log',
  'pppd-dns',
  'prometheus',
  'rsync',
  'samba',
  'samba-ad-dc',
  'saned',
  'speech-dispatcher',
  'unattended-upgrades',
  'uuidd',
  'lvm2-lvmpolld' ]
 
     
    