I have two types of manipulations I would like to make with immutability-helper, but I am very stuck.
I have this data, mocking the results from an API:
var test_data = {
title: "Potato",
sounds: [
{ sound_name: "Fork", id: 27 },
{ sound_name: "Spoon", id: 28 },
{ sound_name: "Knife", id: 29 }
]
};
Type 1 - Change a sound_name, when I have the index
If I know the index of the sounds array, how do I change one of the sound_name? I expect to use update(test_data, $merge ...). What I've made so far doesn't work so I haven't pasted it here.
Type 2 - Change a sound_name, when I know the ID
If I know the ID of the sound, which is a property of an object within the sounds array, is there a concise way of using update? If so, I'd love to see it. Otherwise, I'll use array.findIndex to get the index.
I really appreciate any help, I've been stuck this weekend.