utilizing a central function to recursively loop through relatively complex data

This is working here on data similar to data in production. Still need to limit writing of the header to once till the header changes.

by Matt Rummler

HTML

<body>
    <section id='firstSection'>
        <div>
            div in the first section
        </div>
    </section>
    <section id='secondSection'>
        <div>
            div in the second section
        </div>
    </section>
</body>

JavaScript

Object.toType = (function toType(global) //taken from https://javascriptweblog.wordpress.com/2011/08/08/fixing-the-javascript-typeof-operator/
{
  return function(obj) 
  {
    if (obj === global) 
    {
      return "global";
    }
    return ({}).toString.call(obj).match(/\s([a-z|A-Z]+)/)[1].toLowerCase();
  };
})(this);
Object.forEach=(function forEach()
{
  return function(obj,fn)
  {
    if(obj.length)
    {
      for (var i = 0, ol = obj.length, v = obj[0]; i < ol && fn(v, i) !== false; v = obj[++i]);
    }
	else
    {
      for (var p in obj) if (fn(obj[p], p) === false) break;
    }
  };
})(this);
/*
***
*/
function findDataToProcess(data,callback,OptionObj)//,i)
{
    alert('beginning of findDataToProcess');
  callback=callback || writeComplexObjectToTargt;
  if(Object.toType(callback)!=='function')
  {
    callback=writeComplexObjectToTargt;//IMPORTANT NOTE: Another likely way to do this is to wrap the callback sent to APP.ajaxSendReceive in another function that accepts the data and then inserts the callback from the calling function/method
  }
//  data=APP.Utilities.removeJSONobjectsArrays(data);
//    alert('@ the beginnnig of findDataToProcess');
  var keyTest=null;
  var contentType=null;
  var allKeys=[];
  var knownContentTypes=[];
//    alert('right before calling the inner looping function loopingFunction');
  loopingFunction(data);
  function loopingFunction(data)
  {
//      alert('in the function loopingFunction');
    Object.forEach(data, function(value, key)
    {
        alert('the key: '+key+' and the value: '+value+' The isNumeric result of the key is: '+isNumeric(key)+' and its typeof value is: '+typeof key+' while the type of value is: '+Object.toType(value));
//        alert('in loopingFunctions loop');
   //   keyTest=key;//APP.Utilities.contentTypeFromKey(key);
      if(Object.toType(value)=='object' && !isNumeric(key))
      {
//          alert('value is an object & is not numeric');
        contentType=key;
       ...