I am searching for a specific object in an array based on the user-provided ID.
var laptops = [{
"name": "Firefox",
"age": 30,
"id": "ab"
},
{
"name": "Google",
"age": 35,
"id": "cd",
"date": "00.02.1990"
},
{
"name": "Microsoft",
"id": "ef",
"age": 40
}
];
getLaptopByAsin(id: string) {
var laptop = this.laptops.find(
(laptopObject) => {
return laptopObject.name === id;
}
);
return laptop;
}
var enter = "cd";
name = this.getLaptopByAsin(enter).name;
age = this.getLaptopByAsin(enter).age;
date = this.getLaptopByAsin(enter).date;
console.log(name)
console.log(age)
console.log(date)