Checking value during recursion

I have a function arrayToList that takes in an array and returns a list in the following format. Eg. for an array [1,2,3], the output is

value: 1,
      rest: {
          value: 2,
          rest: {
             value: 3,
             rest: null

I wrote the function with a recursion call as follows :

function arrayToList(arr) {
	for(let i = 0 ; i < arr.length ; i++){
		return {
			value : arr[i],
			rest : arrayToList(arr.slice(i + 1,arr.length))

However, the output is as follows
{ value: 1, rest: { value: 2, rest: { value: 3, rest: undefined } } }

How do I ensure I get a value of null for the last rest attribute in result body keeping the recursive nature of the code logic unchanged?

if the array is empty, the loop is not executed, and a function without a return statement returns undefined

also, your loop is useless, as it never go after first execution as you have a return statement inside it

The loop is needed for the value of i to change. And the loop does make a difference . I got around this issue by checking if the length of array is 1 i.e only last item is left , then assign rest to null @ilenia