# 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.

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

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