# Defining a function that modifies a list [closed]

I have the a list A and I want to define a function f that takes out the $$i$$-th element from the list A:

A = {5, 2, 30, 14}

f[1] = 5;
f[2] = 2;
f[3] = 30;


I've tried f[i_] = A[[i]] but it didn't work.

## closed as off-topic by march, m_goldberg, rhermans, garej, Henrik SchumacherJul 8 at 17:24

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – march, m_goldberg, rhermans, garej, Henrik Schumacher
If this question can be reworded to fit the rules in the help center, please edit the question.

• But why do this when you can just do A[[2]]? – march Jul 6 at 15:52
• You are right, it is not necessary to define a function for this. – Igor Jul 7 at 15:32

f[i_] := A[[i]]