How to convert object containing Objects into array of objects

前端 未结 7 1496
忘了有多久
忘了有多久 2020-11-29 04:41

This is my Object

var data = {
    a:{\"0\": \"1\"},
    b:{\"1\": \"2\"},
    c:{\"2\": \"3\"},
    d:{\"3\": \"4\"}
};

This is the output

相关标签:
7条回答
  • 2020-11-29 05:48

    This works for me

    var newArrayDataOfOjbect = Object.values(data)

    In additional if you have key - value object try:

    const objOfObjs = {
       "one": {"id": 3},
       "two": {"id": 4},
    };
    
    const arrayOfObj = Object.entries(objOfObjs).map((e) => ( { [e[0]]: e[1] } ));
    
    

    will return:

    [
     "one": {"id": 3},
     "two": {"id": 4},
    ]
    
    0 讨论(0)
提交回复
热议问题