I have an object
var students = { 0: "Ann_L", 1: "Bob_P", 2: "Cat_C" }
How can I get an array from the object with its key and value?
var array = [
{ "Id": 0, "Value": "Ann_L", "Name": "Ann L" },
{ "Id": 1, "Value": "Bob_P", "Name": "Bob P" },
{ "Id": 2, "Value": "Cat_C", "Name": "Cat C" }
]
I have the values of the object but not the keys for "Id"
var array = Object.entries(students).map(([_, student ]) =>
({
Name: student.replace(/_/g, " "),
Id: ?,
Value: student
})
_contains your key