I am working with an array that is filled with objects
let objectArray = [{
id: 1,
name: "John"
}, {
id: 2,
name: "Bill"
}, {
id: 3,
name: "Mike"
}];
Next, I create a proxy with a set handler using my array as the target
let proxy = new Proxy(objectArray, {
set: function(target, property, value) {
//Handle the set action
})
})
When I try to use forEach
on the proxy:
proxy.forEach((element) => {
element.name = "updated value";
});
The set trap in my proxy does not trigger, even though array manipulation methods like p.push() do.
Which trap should I use in this scenario?