How to change a Javascript object with a dynamic path?

Im trying to change a variable list with newList. The problem is that i dont know how to change the list when it got path added with a function.

Add string to object

Object.byString = function(o, s) {
    s = s.replace(/[(w+)]/g, '.$1'); // convert indexes to properties
    s = s.replace(/^./, '');           // strip a leading dot
    var a = s.split('.');
    for (var i = 0, n = a.length; i < n; ++i) {
        var k = a[i];
        if (k in o) {
            o = o[k];
        } else {
            return;
        }
    }
    return o;
}

Return path

function getPath2(){
   const split = get("path").split('~');
   var newSplit = "";
   for (key in split){
      if(!split[key] == ""){  
        newSplit = newSplit + "."+split[key]+"";
      }
   }
   return newSplit;
   }
//  this works
//  {afas: {…}, fa: {…}, fas: {…}, af: {…}}
console.log(Object.byString(list, getPath2()));

//  this works
// {afas: {…}, fa: {…}, af: {…}, fas: {…}}
console.log(newList);

// This is not working
Object.byString(list, newPath) = newList;

Error I get back:
script.js:420 Uncaught ReferenceError: Invalid left-hand side in assignment
at HTMLLIElement. (script.js:420:32)