Javascript replace key value in object list with user input

I have an object as below.

let data= {
  "" : { name: 'Tom', age: '21'},
  "26": { name: 'Harry', age: '22'}
}

The first entry in the list is created when a user clicks on add button to add a new entry.
I take the key value for the first entry from the input field. So if the input value is 8 the new data should be like below.

let data= {
  "8" : { name: 'Tom', age: '21'},
  "26": { name: 'Harry', age: '22'}
}

How can I achieve that?

49 thoughts on “Javascript replace key value in object list with user input”

Leave a Comment