Array,List,Object


#1

<PLEASE USE THIS TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>
Hi, I’d like to create a function whose name is “arrayToList”, however, I don’t know why it doesn’t work , and keeps showing “Unexpected token if”, can anyone help me?

Results I want is

console.log(arrayToList([10, 20]));
// → {value: 10, rest: {value: 20, rest: null}}

However, it keeps showing “Uncaught SyntaxError: Unexpected token if (line 9)”

Replace this line with your code.

function arrayToList(arrayx){
 for(var i=0;i<arrayx.length;i++)
  var list={
    value: array[i],
    rest: {
    value: array[i+1],
     rest: null
          }
        }
         return list;
      }
<do not remove the three backticks above>

#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.