Javascript appending object doesn't guarantee order

前端 未结 3 2024
暖寄归人
暖寄归人 2021-01-16 02:54

I have looked at this question in stack overflow about objects guaranteeing order. Does JavaScript Guarantee Object Property Order?

some says they guarantee, some s

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-16 03:38

    I think what you're looking for is a Map() object. See here -> Map and Set

    const arrayObject = [
      {id:'a123', bar:'hello'}, 
      {id:'a321', bar: 'foo'},
      {id:'a234', bar: 'more'},
      {id:'a735', bar: 'words'},
      {id:'a167', bar: 'added'},
      {id:'a857', bar: 'now'},
    ];
    
    var newObj = new Map();
    
    for (var i=0; i

提交回复
热议问题