Extracting Headings for Metadata Menu using DataviewJS

Hello, I’m quite new to Obsidian especially to the plugins side. I’m trying to figure out how metadata menu uses values from dataview query.

What I’m trying to do

I’m trying to use every heading 1 of a note as the values for a field. I’m using multi field type, but I imagine it wouldn’t be different with the other supported types. I can already extract the headings, but the problem is to match it with the expected format of metadata menu I believe.

Things I have tried

Here’s where I’m at right now.

const page = dv.page("Test1.md");
var output = []

const content = await dv.io.load(page.file.path);
const lines = content.split('\n');

for (const line of lines) {
	if (line.startsWith("# ")) {
		output.push(dv.paragraph(line))
	} else {
		continue;
	}
}

dv.list(output)

I’ve also tried using dv.paragraph(output), return output, among others.

Any help would be much appreciated. :smiley:

So I’ve decided to try wrapping the login inside a function to be able to have a return value:

const page = dv.page("Test1.md");
const output = [];

const content = await dv.io.load(page.file.path);
const lines = content.split('\n');
	
function getHeaders() {
	for (const line of lines) {
		if (line.startsWith("# ")) {
			output.push(line.substring(2));
		} else {
			continue;
		}
	}
	
	return dv.array(output);
}

getHeaders();

It seems to be working just fine when I tried it on a note, but still no luck for the metadata menu. Now I have no clue where the problem lies since the format should be correct this time.