score:0

<html>
</html>

<script>
    const data = {
        "0": {
            "id": 1912,
            "title": "Books",
        },
        "1": {
            "id": 1958,
            "title": "Brands",
        },
        "2": {
            "id": 2037,
            "title": "Logo",
        },
        "3": {
            "id": 2038,
            "title": "Colour",
        },
    }
    console.log("before: ", data)
    let data1 = []

    for (var k in data) {
        var d = data[k];
        data[k]
        data1[d.id] = d
        console.log(d)
        console.log(data1)
    }
</script>

score:0

const data = {
  "0": {
      "id": 1912,
      "title": "Books",
  },
  "1": {
      "id": 1958,
      "title": "Brands",
  },
  "2": {
      "id": 2037,
      "title": "Logo",
  },
  "3": {
      "id": 2038,
      "title": "Colour",
  },
}

const result = Object.values(data).reduce((acc,curr)=>{
  acc[curr.id] = curr
  return acc
},{})

console.log(result)

score:1

let newObj = {}
Object.keys(data).map(x => {
    newObj[data[x].id] = data[x]
})

console.log(newObj)

Related Query

More Query from same tag