sergey-t
4/18/2018 - 9:19 AM

deleteIn.js

const deleteIn = (arr, obj) => {
  const newObj = Number.isInteger(arr[0]) ? [] : {};
  
  Object.keys(obj).forEach(k => {
    if(k !== arr[0]) {
     newObj[k] = obj[k]; 
    }
  });
  
  if(arr.length > 1) {
     newObj[arr[0]] = deleteIn(arr.slice(1), obj[arr[0]]);
  }
  
  return newObj;
}
// ---------
const obj = {a:1, b:2, c: { d: 3 }};
const obj2 = {a:1, b:2, c: { d: [{k: 100}, {k: 200}, {k: 300}] }};

console.log(deleteIn(['c'], obj));
console.log(deleteIn(['c', 'd', 0], obj2));