Answers for "sort object string js"

26

sort array of object js

const books = [
  {id: 1, name: 'The Lord of the Rings'},
  {id: 2, name: 'A Tale of Two Cities'},
  {id: 3, name: 'Don Quixote'},
  {id: 4, name: 'The Hobbit'}
]

books.sort((a,b) => (a.name > b.name) ? 1 : ((b.name > a.name) ? -1 : 0));
Posted by: Guest on April-08-2021
1

sort objects in array js

function createDropDowns() {
    for (const [key, val] of Object.entries($pgns["nmea2000"])) {
      pgnList = [...pgnList, val];
      fieldsList[val.title] = val.fields;
      fieldsListOut[val.title] = val.fields;
    }
    pgnList.sort((a, b) =>
      a.title > b.title ? 1 : b.title > a.title ? -1 : 0
    );
}

pgnList = [
  	{pgn: '065280', manufacturer: '161', title: 'Proprietary - Set Serial Number', fields: Array(6), route: '/nmea2000/data/{busNumber}/by_instance/{instance}/065280/{field}'}
	{pgn: '065280', manufacturer: '257', title: 'Engine Status Parameters, Dynamic', fields: Array(10), route: '/nmea2000/data/{busNumber}/by_instance/{instance}/065280/{field}'}
	{pgn: '065284', manufacturer: '257', title: 'Display Communication Status', fields: Array(12), route: '/nmea2000/data/{busNumber}/by_instance/{instance}/065284/{field}'}
	{pgn: '065289', manufacturer: '161', function: '1', title: 'Proprietary - Set Volume and Capacity', fields: Array(8), …}
	{pgn: '065289', manufacturer: '161', function: '2', title: 'Proprietary' }
]
Posted by: Guest on September-30-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language