JSFiddle - React, Tailwind, and code Playground

HTML

<div id="1"></div>
<div id="2"></div>

JavaScript

f1("obj.key"); 

function f1(val){
   obj={
      key : "Hello World"
   };
   
   var current = window;
   var attributes = val.split( '.' );
    for (var i = 0; i < attributes.length; i++) {
            current = current[attributes[i]];
    }
   $('#2').text( obj.key );     // works fine
   $('#1').text( current ); // does not work
}