I am trying to add an object to existing JSON data in TypeScript. I am new to TypeScript and have created an array variable called jsonArrayObject, which contains a boolean[] type. This jsonArrayObject holds a contactModel object with properties like fname, lname, id, and mobile. Below is the code snippet that I tried. Can someone please assist me?
let jsonArrayObject: boolean[] = [];
jsonArrayObject=[{
contactModel:{
fname:"vboyini",
lname:"simha",
id:"1",
Mobile:"99768999"
}
}];
var modelData :String={
fname:"vboyini2",
lname:"simha2",
id:"2",
Mobile:"799768999"
}
Now, I want to prepend the array item (contactModel object) into the jsonArrayObject. I attempted the following code:
this.jsonArrayObject.unshift({"contactModel":any=modelData})
The above code is not working. Can someone please help me figure out how to achieve this? Thank you.