alex-009
alex-0092w ago

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"));
}
}
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"));
}
}
1 Reply
crowlKats
crowlKats2w ago
just console.log should print its properties and methods. alternatively you can try console.logging the result of Deno.inspect, maybe with some of the options enabled