0

In the case that I have a javascript object with the following structure:

var furniture_reviews = 
{
    tables: [
        ...
    ],
    chairs: [
        {ikea_basic: 'bad', ikea_fancy: 'ok'},
        {bohus_1: 'good', bohus_2: 'good'},
        {chairheaven_red: 'mediocre'}
    ]
}

The object can of course be of arbitrary length and arbitrary structure, but let's say that I find the review of the ikea_basic chair unfair and would like to change it. However I only have access to a list containing the path to reach that review, see following code example:

var ikea_review = ['chairs', 0, 'ikea_basic']

Given only furniture_reviews and ikea_review. How can I use this list only to successfully traverse to the correct review and make persistent edits to furniture_reviews? I need a solution that can successfully operate any arbitrary javascript object.

Alien13
  • 462
  • 2
  • 8
  • 23

0 Answers0