Below is a sample of a JSON array containing information about cars.
var cars = {
"cars": {
"john": [],
"alex": [
"ford"
],
"hilton": [],
"martin": [
"ford",
"ferrari"
],
"david": [
"Lamborghini"
],
...
}
}
I am looking to extract arrays from this data structure using Typescript but have been unsuccessful. I also have another JSON array with just names which I'm unable to utilize.
var names = {
"names": [
"john",
"alex",
"hilton",
"martin",
"david",
...
]
}
Here is the approach I've tried, but it's not working as expected.
let aryCars: string[][] = [];
names.map((name: string) => {
cars[name].map((car: string) => {
aryCars[name].push(car);
});
});
When attempting this, I encounter the following error:
Element implicitly has an 'any' type because index expression is not of type 'number'.
If you have any insights on how to solve this issue, please share. Thank you.