Accessing multi-reference items from dataset query

Hello,

I have a dataset called “Printmaterial” with a multi-reference field called “2x3Sizes”.
As you might have guessed the an item in the “2x3Sizes” field can have multiple items.
If I wanted to query the “Printmaterial” dataset, including the reference to “2x3Sizes”, I guess you would do something like this:

const getMaterial = async()=>{
		const materialQueryResult = await wixData.query("Printmaterial")
		.include("2X3Sizes")
		.find();
		materials = materialQueryResult.items;
		console.log(materials);
		};

That returns an object that looks like this:

My question is, how do you access the items in the “2X3Sizes” field.
If I expand the “2X3Sizes” fields in the output, we get this:

We can see that there is an item with title “12x18”.
How do I access this title from my original query?

Thank you in advance for your help!

maybe add a loop through each material

materials.forEach(material => {
    const sizes = material["2X3Sizes"];
    
    sizes.forEach(sizeItem => {
      console.log(sizeItem.title); 

@Dan_Suhr Thank you so much for your help. That worked! :grinning:

1 Like

No worries. Glad it helped.