JSFiddle - React, Tailwind, and code Playground

by joznox

JavaScript

const data = [
	{
  	date: "2023-05-01T20:58:51Z",
    entries: 2,
    visits: undefined,
    miles: undefined,
    data: {
    	timeIn: ["2023-05-01T18:00:00Z"],
      timeOut: ["2023-05-01T20:00:00Z"],
      type: ["Client"],
      hours: ["2"]
    }
  },
  {
  	date: "2023-05-10T20:58:51Z",
    entries: 4,
    visits: undefined,
    miles: undefined,
    data: {
    	timeIn: ["2023-05-10T18:00:00Z", "2023-05-10T16:00:00Z" ],
      timeOut: ["2023-05-10T20:00:00Z", "2023-05-10T18:00:00Z"],
      type: ["Client"],
      hours: [2, 2]
    }
  },
  {
  	date: "2023-05-01T20:58:51Z",
    entries: undefined,
    visits: 2,
    miles: undefined,
    data: {
    	timeIn: undefined,
      timeOut: undefined,
      type: undefined,
      hours: undefined
    }
  },
  {
  	date: "2023-05-10T20:58:51Z",
    entries: undefined,
    visits: 4,
    miles: undefined,
    data: {
    	timeIn: undefined,
      timeOut: undefined,
      type: undefined,
      hours: undefined
    }
  },
  {
  	date: "2023-05-01T20:58:51Z",
    entries: undefined,
    visits: undefined,
    miles: 20,
    data: {
    	timeIn: undefined,
      timeOut: undefined,
      type: undefined,
      hours: undefined
    }
  },
  {
  	date: "2023-05-10T20:58:51Z",
    entries: undefined,
    visits: undefined,
    miles: 40,
    data: {
    	timeIn: undefined,
      timeOut: undefined,
      type: undefined,
      hours: undefined
    }
  },
]

const first = data.map(i => (
	{
  	date: new Date(i.date).toLocaleDateString(),
    entries: i.entries,
    visits: i.visits,
    miles: i.miles,
    data: {
    	timeIn: i.data.timeIn,
      timeOut: i.data.timeOut,
      type: i.data.type,
      hours: i.data.hours
    }
  }
))

console.log("first: ", first)

function scrub(object) {
    Object
        .entries(object)
        .forEach(([k, v]) => {
            if (v && typeof v === 'object') {
                scrub(v);
            }
            if (v && typeof v === 'object' && !Object.keys(v).length || v ===...