# How would I convert an array of 1s and 2s to an array of 3s and 4s?

``````local array1 = {1,2,1,2,2,1,1,1}
``````

I want to turn this into:

``````local array2 = {3,4,3,4,4,3,3,3}
``````

If you just want a program that does specifically that, you just need to fetch the index of the number you’re trying to replace and insert a new one in its position.

``````local array1 = {1, 2, 1, 2, 2, 1, 1, 1}

for position , number in pairs(array1) do
if number == 1 then
array1[position] = 3
else
array1[position] = 4
end
end
``````

This is accomplished by editing the same array, which I believe is what you’re trying to do? If you just want a brand new array, just use `table.insert` at the same order and it should work just fine as well.

This works, thank you for the help.

``````local function incrementValues(t, inc)
for i, _ in ipairs(t) do
t[i] += inc
end
end

local t = {1, 2, 1, 2, 2, 1, 1, 1}
incrementValues(t, 2)
for _, v in ipairs(t) do
print(v) --3, 4, 3, 4, 4, 3, 3, 3
end
``````

Here’s a generic table value incrementer.