From a Basic Number input make an array

Hello

I’m trying to figure out if this is possible at all.

I have a number field that is entered somewhere 1 to 50.

I’m trying to figure out how to make an array or even a text field that behaves like the examples below.

Eg. Number: 3

Output 1,2,3

Eg. Number: 10

Output: 1,2,3,4,5,6,7,8,9,10

Is something like this possible?

Thank you for your time.

The way I would do this…

  1. Create a column that has all the possible numbers… ie:
1,2,3,4,5,6,7...
  1. Create column for user input (number).
  2. Create a math column that is user input * 2 - called padding
  3. Finally, create a column that will truncate the possible numbers like so:

In the ending… put a space

1 Like

I would use a bit of javascript in a javascript column that will take the input and return a comma delimited list of numbers. The p1 parameter would be your input number column.

function generateSequence(inputNumber) {
  if (typeof inputNumber !== 'number' || inputNumber <= 0) {
    return 0;
  }

  const sequenceArray = Array.from({ length: inputNumber }, (_, index) => index + 1);
  const commaSeparatedSequence = sequenceArray.join(', ');

  return commaSeparatedSequence;
}

return generateSequence(p1);

If you ultimately want an array, then you can also create a Spit Text column that will convert the result from the javascript column into a true array.

2 Likes

Two solutions for you :slight_smile:

Thank you guys

My original idea was to a giant If Then Else Column but that wouldn’t be very dynamic and a simple mistake could be missed.

I appreciate the help.

2 Likes