javascript - Sort Objects in 2nd level array -
Hi how I will find out how to sort it is a sample of my array below.
  product_sort_arr = [[{name: 'particle'}, link: value}], [{name: 'bio-part 112', link: value}], [], etc. . . ];    I hope you can visualize the sample.  
 So far I have tried to use and it is still not working yet it is still trying to fix it.   
 Expected Return  
  product_sort_arr.sort (function (a, b) {return a.name - b.name;})  < Pre>  product_sort_arr = [[{name: 'bio-part 112'}, link: value}], [{name: 'particle', link: value}], [], etc. . . ];     
  I'm not sure what your array should be, but now with some Errors have been defined. This example is working. I hope this will move you in the right direction.  
  var product_sort_arr = [[{name: 'particle', link: 'value'}], [{name: 'bio-part 112', link: 'value'}],] ; Product_sort_arr.sort (function (a, b) {if (a [0] .name & gt; b [0] .name) {return 1;} if (a [0] .name & lt; b [0] Name) {return -1;} return 0;}); (I = 0; i & lt; product_sort_arr.length; i ++) for {console.log (product_sort_arr [i] [0] .name); } Check on     
 Note that array is an array of objects, so that you get to  product_sort_arr [0] [0] .name  And  product_sort_arr [1] [0] .name    
 
  
Comments
Post a Comment