按属性对对象数组进行排序?

时间:2012-01-17 16:23:03

标签: javascript sorting

  

可能重复:
  Sorting objects in an array by a field value in JavaScript

  1. 用field1,field2或field3对“行”进行排序的最佳方法是什么?

  2. 如果field1,field2或field3是非数字值(字符串或日期),如何才能对这些不同的数据类型进行排序呢?

    var Id = 0;
    var rows = new Array(); // I want to sort this array by either field1, field2, or field3
    rows[0] = (1, 3, 5);
    rows[1] = (-2, 4, -6);
    
    function Row(field1, field2, field3) {
        this.RowId = Id++;
    
        this.Field1 = field1;
        this.Field2 = field2;
        this.Field3 = field3;
    }
    

0 个答案:

没有答案