by adamredwoods · 4y ago · 0 comments
For example:
const userdata = [ { name: "Emma", age: 21, hobby: { reading: true, gaming: false, sport: "tennis" }, class: ["Java", "Go", "Nginx"] }, { name: "John", age: 22, hobby: { reading: true, gaming: false, sport: "football" }, class: ["JavaScript", "HTML", "CSS"] }, ]
const newdata = { knitting: true }
And then, the task is to make a utility function to find "name: John", then "hobby" and append newdata in the "hobby"object. Try to apply immutability. Try to do without the overhead of JSON string conversion.
const newobj = insertIntoObject( obj, ["name:John", "hobby:*"], newdata )