I am working on an angular app. I am receiving an index from html. Code is as follows:
save(index){
//this method will be called on click of save button
}
In my component I have a array as follow
data = [{
"name":"Rosy"
},
{
"name":"julia"
}]
In this save method I want to a add sub array for the index which I receive in save method. Suppose if I get index as 0, then I want to add subarray for 0th index in data array and my resultArray will be as follows:
data = [{
"name":"Rosy",
"Address":[{
"city":"London" // this value I have in a variable in component
}]
},
{
"name":"julia"
}]
Suppose, again I receive 0th index, and now city is "mumbai", then data will be added at
data = [{
"name":"Rosy",
"Address":[{
"city":"London" // this value I have in a variable in component
},
{
"city": "mumbai"
}
]
},
{
"name":"julia"
}]
Same follows for other indexs and elements. How can I do that?