I am currently working on a Typescript project where I need to extract the value of a variable with the same name as a property in a JSON object.
Here is an example of my JSON data:
let assets = [
{
"properties":{
"title":"totalCars"
}
},
{
"properties":{
"title":"totalBikes"
}
}
];
These are some sample variables that I have:
let totalHomes: number = 235,
totalBikes: number = 56,
totalCars: number = 127,
totalBoats: number = 19,
totalTrucks: number = 8
This is what I am trying to achieve:
let vehicleCounts: Array<number>
for (let asset of assets) {
// extracting the value from the corresponding property in the JSON object
}
The desired outcome would be:
vehicleCounts = [127, 56]