#Alligning text while joining strings

4 messages · Page 1 of 1 (latest)

turbid pine
const spaceCount = 50 - (item.Name.length + item.Weight.toString().length +4 );
const combined = item.Name +  item.Weight.toString().padStart(spaceCount , " ") + " gms";
optionElement.value = combined ;
suggestionsList.appendChild(optionElement);

I am doing this to allign on the weight in one end but as in the screenshot some of them are at different lengths . Why is this? Not sure if this is the place

devout smelt

Because you don’t use a monospaced font. So while they are the same amount of characters on each line they aren’t the same length in count of pixels

Easiest way to accomplish this is put it in a codeblock

turbid pine

which part exactly do i put in a codeblock..