sort object properties and JSON.stringify

后端 未结 22 2311
南方客
南方客 2020-11-28 05:44

My application has a large array of objects, which I stringify and save them to the disk. Unfortunately, when the objects in the array are manipulated, and sometimes replac

22条回答
  •  鱼传尺愫
    2020-11-28 06:24

    Try:

    function obj(){
      this.name = '';
      this.os = '';
    }
    
    a = new obj();
    a.name = 'X',
    a.os = 'linux';
    JSON.stringify(a);
    b = new obj();
    b.os = 'linux';
    b.name = 'X',
    JSON.stringify(b);
    

提交回复
热议问题