Erlang - nth



Returns the Nth element of List.

Syntax

nth(N,List)

Parameters

  • N − The nth value to return from the list.

  • Lst − The list of elements.

Return Value

Returns the Nth element of List.

For example

-module(helloworld). 
-import(lists,[nth/2]). 
-export([start/0]). 

start() -> 
   Lst1 = [1,2,3], 
   io:fwrite("~p~n",[nth(2,Lst1)]).

Output

When we run the above program, we will get the following result.

2
erlang_lists.htm
Advertisements