I have a JSON Object that comes from my MongoDB database. I am using this object to display it in an HTML Select element (I only show the "graDes" field).
I want to add a new element to be able to have as the first Item an option that says "Select Degree".
For this I saw the alternative of adding a new element to the JSON using Typescript.
I've tried many ways but I didn't get a result :( I would appreciate if you could give me some recommendation, thanks.
[
{
"estCod": {
"_id": "5d82a03b2cfab80f3cb9cd7a",
"estCod": "001",
"estNom": "Activo",
"estDes": "...",
"timestamp": "2019-09-18T21:23:07.222Z",
"__v": 0
},
"_id": "5da9584878ec3e12004f670b",
"graNum": "5",
"graDes": "5to Grado",
"colCod": {
"estCod": "5d82a03b2cfab80f3cb9cd7a",
"_id": "5d8d1b245393e91480b3447b",
"colNom": "Siervos de Jesus",
"colRuc": "12345678962",
"timestamp": "2019-09-26T20:10:12.012Z",
"__v": 0
},
"timestamp": "2019-10-18T06:14:32.175Z",
"__v": 0
},
{
"estCod": {
"_id": "5d82a03b2cfab80f3cb9cd7a",
"estCod": "001",
"estNom": "Activo",
"estDes": "...",
"timestamp": "2019-09-18T21:23:07.222Z",
"__v": 0
},
"_id": "5da95e3978ec3e12004f6713",
"graNum": "2",
"graDes": "2do Grado",
"colCod": {
"estCod": "5d82a03b2cfab80f3cb9cd7a",
"_id": "5d8d1b245393e91480b3447b",
"colNom": "Siervos de Jesus",
"colRuc": "12345678962",
"timestamp": "2019-09-26T20:10:12.012Z",
"__v": 0
},
"timestamp": "2019-10-18T06:39:53.702Z",
"__v": 0
}
]
If the json values are already parsed and are in an array, you can insert a value at the beginning of it with unshift()
This will add a custom object to the array