In a angular project, I have following interface:
export interface FruitsType {
id: String;
name: String;
selected : String;
}
And following JSON:
{
[
{"id" :"f1", "name": "apple", "selected": "false"},
{"id": "f2" , "name":"orange", "selected": "false"}
]
}
The GOAL is to assign name of the fruits to a checkbox.
I have read the JSON file using a service--in the ngonINIT-- which it's output is as follows:
0:{id: "f1", name: "apple", selected: "false"}
1:{id: "f2", name: "orange", selected: "false"}
I want to assign the id and name of above output to the corresponding in the interface and push it to an array. Is that possible? HOW?
here what I have tried
// here is my service:
getJSON (): Observable<FruitsType[]> {
return this.http.get<FruitsType[]>((this.configUrl))
}
// and here is how i get the response:
this.jsonService.getJSON().subscribe(response => {
// THAT WORKS FINE
console.log("here is the forst fruit: " + response[1].name);
console.log("here is the forst fruit: " + response[1].id);
//console.log(response.length);
// WANTS TO ADD THE RESPONSE TO AN INTERFACE
for (let i=0; i<response.length; i++){
this.fruitInterface.push({id: response[i].id, name: response[i].name, selected : response[i].selected });
}
console.log("lenght " + this.fruitInterface.length);
})
}
the this.fruitInterface has the lenght of 2, meaning the values has been added. BUT I CANNOT READ THEM :(( I do : this.fruitInterface.name ==> gives error in array to say: this.fruitInterface[i].name ==> does not work
PLEASE HELP ME

FruitsTypewherever needed.interface whatever { fruites: FruitsType[] }, but it's already an array.