I am seeking a solution to access the "description" property of objects within an array and utilize a string cutting method, such as slice, in order to return an array of modified objects. I have attempted using for loops but have been unsuccessful.
Here is the code:
let cars = [
{
"status": "disabled"
},
{
"status": "active",
"store": true,
"models": [
{
"description": "4 doors, 0km/h, no breakdowns",
"color": "black",
"price": 100.000,
},
{
"description": "2 doors, 30.000km/h, some breakdowns",
"color": "black",
"price": 20.000,
},
{
"description": "4 doors, 120.000km/h, no breakdowns",
"color": "red",
"price": 50.000,
}
]
}
]
I can extract the desired property and use slice() within a loop to modify it, however I am struggling with returning this updated array of objects when calling "carsTwo". Here is what I have tried:
let carsTwo= cars[1].models;
//remove unwanted properties from new array
for(let i=0; i<carsTwo.length; i++) {
delete carsTwo[i].color;
delete carsTwo[i].price;
}
//apply slice() to every "description" property value, successfully displayed in console.log...
for(let i=0; i<carsTwo.length; i++) {
carsTwo[i].description.slice(3)
}
My objective is to return the array of objects containing only the description property, with slice applied.
Note: I am a beginner in programming.