alex-009A
Denoβ€’16mo agoβ€’
1 reply
alex-009

Is there a function which can print a structure in deno/typscript similar to print_r in php ?

I would like to know which attributes and structure members a struct have and asked my self if there is something similar in deno/typscript to php https://www.php.net/manual/en/function.print-r.php

I use deno 2.0.0-rc.5.
Here the code which I use. The questioned line is this console.log(anchorTag.) //<= How to dump anchorTag?
import { DOMParser } from "jsr:@b-fuze/deno-dom";
const baseURL = "https://deno.com";

const client = Deno.createHttpClient({
  poolIdleTimeout: 60,
  poolMaxIdlePerHost: 8,
  http1: true,
  http2: true,
});

const response = await fetch(baseURL, {
  client: client,
  headers: {
    "User-Agent": "My-UA",
  },
});

console.log(response.status); // e.g. 200
console.log(response.statusText); // e.g. "OK"
const text = await response.text();
const doc = new DOMParser().parseFromString(text, "text/html");
console.log(doc.head);

const anchorTags = doc.querySelectorAll("script");
for (const anchorTag of anchorTags) {
  if (anchorTag.getAttribute("src") == null) {
    console.log(anchorTag.) //<= How to dump anchorTag?
    continue;
  }
  if (anchorTag.getAttribute("src")?.startsWith("/")) {
    console.log(baseURL + anchorTag.getAttribute("src"));
  } else {
    console.log(anchorTag.getAttribute("src"));
  }
}
Was this page helpful?