Joomla 4. Компонент K2 и форк K2ForJ4 (18 янв 2024)

Если вас, как и меня, достало выслушивать (вычитывать) бесконечные обещания разработчика K2 опубликовать версию компонента K2 под Joomla 4 (без чего невозможно реализовать апгрейд from Joomla 3 to Joomla 4) - воспользуйтесь форком K2ForJ4. Который в данный момент установлен и без каких-либо проблем работает на этом веб-сайте.

Rails: how do I add element to an array?

Больше
6 года 7 мес. назад #1 от serge
serge создал тему: Rails: how do I add element to an array?
Create an array:
Code:
@array = [123, 456, 789, 012, 345]

Then you can push or shovel the new value in:
Code:
@array << element

or
Code:
@array.push(element)

Convert String to Array. Alternately if you want the numbers to remain strings for some reason, just convert the string into an array using the String#split method:
Code:
@array = "123,456,789,012,345".split(',') #=> ['123', '456', '789', '012', '345']

Just append to String. You could also just add the new value (as a string) to the existing string:
Code:
@array += ",#{element}"

So if element were set to 678, this would turn the integer into a string and add it to the existing string with a leading-comma.

If you want the values in your array to remain in a string, you can use the split method:
Code:
@array.split or @array.split(',')

The following lines add the element as the last element in the array:
Code:
array[array.length] = element array += [element] array << element array.push(element) array.append(element)

To add it at a specific position, use insert:
Code:
array.insert(position, element)

А я смогу! - А поглядим! - А я упрямый!

Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.

Dev banner 3
Работает на Kunena форум