I am trying to write a function that finds the biggest value among JSON arrays and then returns another value from the array where the biggest value was found. In concrete: Find the table with the highest (i.e. most recent) creationTime and then return the id of that table. The function should return "clickup-test-example:ClickUp_Teams.ClickUp_Teams_1619170399502"
{
"totalItems": 3,
"kind": "bigquery#tableList",
"etag": "PCARXzLSMg+ycECbmPnMDQ==",
"tables": [
{
"kind": "bigquery#table",
"id": "clickup-test-example:ClickUp_Teams.ClickUp_Teams_1618403016322",
"tableReference": {
"projectId": "clickup-test-example",
"datasetId": "ClickUp_Teams",
"tableId": "ClickUp_Teams_1618403016322"
},
"type": "TABLE",
"creationTime": "1618403016433",
"expirationTime": "1623587016433"
},
{
"kind": "bigquery#table",
"id": "clickup-test-example:ClickUp_Teams.ClickUp_Teams_1619168558388",
"tableReference": {
"projectId": "clickup-test-example",
"datasetId": "ClickUp_Teams",
"tableId": "ClickUp_Teams_1619168558388"
},
"type": "TABLE",
"creationTime": "1619168558487",
"expirationTime": "1624352558487"
},
{
"kind": "bigquery#table",
"id": "clickup-test-example:ClickUp_Teams.ClickUp_Teams_1619170399502",
"tableReference": {
"projectId": "clickup-test-example",
"datasetId": "ClickUp_Teams",
"tableId": "ClickUp_Teams_1619170399502"
},
"type": "TABLE",
"creationTime": "1619170399591",
"expirationTime": "1624354399591"
}
]
}
I tried writing this function based on these two threads: Getting max value(s) in JSON array and Finding the max value of an attribute in an array of objects , but I don't know how to write the Math.max function. Any other solution would be appreciated as well. Thanks in advance!
function findNewestTables() {
const tables = BigQuery.Tables.list('clickup-test-307314','ClickUp_Teams'); // returns the JSON file above
const newestTables = Math.max(tables.tables.map(function(o) {
return o.id;
}));
console.log(tables);
console.log(newestTables);
};