0

I need to sort an array of objects by columnId, preferably using lodash. The array is like this:

lines: lineId: 1,lineAbbreviation: "",workingListId: 4208,workingListType: 0,sortOrder: 0,holdType: 1,[tripSummary: - [- {columnId: 24,columnType: 1,value: "2.00"},- {columnId: 28,columnType: 5,value: "0.66"},- {columnId: 29,columnType: 6,value: "0.00"},- {columnId: 23,columnType: 0,value: "152.56"},- {columnId: 25,columnType: 2,value: "24"},- {columnId: 26,columnType: 3,value: "30"},- {columnId: 27,columnType: 4,value: "101.36"},- {columnId: 30,columnType: 7,value: "0.00"},- {columnId: 31,columnType: 8,value: "0.5"},- {columnId: 32,columnType: 9,value: "0"},- {columnId: 33,columnType: 10,value: "1"}]}]

If this is not enough info let me know. I don't know what else I can add though. Its pretty straight forward sorting the array, I just cant figure out how to do it.

UPDATE What I need is the tripSummary to be sorted by columnID. there are more than one line object, actually there is about 200+, I only added one because there would be way too much code. There is one tripSummary object per line object. So in the end each line will be sorted by tripSummary.columnId. Hope this clears more up.

ayordy67
  • 41
  • 1
  • 1
  • 8
  • 3
    I don't understand what the '-' signs are doing in there. – rasmeister Feb 03 '17 at 17:30
  • What have you tried? The documentation is pretty straightforward, so you may have to be more specific about what you're stuck on. – 4castle Feb 03 '17 at 17:34
  • @rasmeister it seem he copy from browser extension to format json data – Tiep Phan Feb 03 '17 at 17:40
  • @rasmeister - yes I copied the json from a chrome extension. – ayordy67 Feb 03 '17 at 17:51
  • 1
    Here is your solution. Check out http://codepen.io/cmlonder/pen/oBWNyY – cmlonder Feb 03 '17 at 19:43
  • @cmlonder this looks excellent. I have one question, maybe you can update your code. the initial list has multiple lines. So there are 100 lines and each line contains a tripSummary. I need to sort the lines by tripSummary.columnId – ayordy67 Feb 03 '17 at 22:23

0 Answers0