Skip to main content

Hi, I am trying to change text properties only on a first occurrence in for loop as shown on a code sample below:


      for (let j = 0; j < countRows; j++) {
console.log(j)
const row = figma.createFrame()
row.clipsContent = false
row.name = 'Row ' + (j+1)
row.layoutMode = "VERTICAL"
row.primaryAxisSizingMode = "AUTO"
row.counterAxisSizingMode = "AUTO"
column.appendChild(row)

const rowTextFrame = figma.createFrame()
rowTextFrame.clipsContent = false
rowTextFrame.name = 'Text ' + (j+1)
rowTextFrame.layoutMode = "VERTICAL"
rowTextFrame.primaryAxisSizingMode = "AUTO"
rowTextFrame.counterAxisSizingMode = "AUTO"
rowTextFrame.paddingTop = 10
rowTextFrame.paddingBottom = 10
rowTextFrame.paddingLeft = 14

row.appendChild(rowTextFrame)

// Generate text

if (j = 0) {
const rowText = figma.createText();
rowText.fontName = { family: "Open Sans", style: "Bold" }
rowText.characters = "Headline";
rowTextFrame.appendChild(rowText);
} else {
const rowText = figma.createText();
rowText.fontName = { family: "Open Sans", style: "Regular" }
rowText.characters = "Edit me";
rowTextFrame.appendChild(rowText);
}

I added console.log(j) to see the output, so I am using my if conditional right

image


And then I added condition if (j = 0) (because the first occurrence would be at 0 always), but when executed Figma will freeze and console output looks like this.

image


It gets stuck on the next loop and whole Figma freezes and I need to manually close it.

What am I doing wrong? Why I cannot use simple IF conditional to execute different code on first for loop occurrence?

In the condition, you used an assignment operator, not a comparison operator.


Reply