Juan Reina Pascual Juan Reina Pascual - 14 days ago 5
Javascript Question

Right syntax of lambda javascript

I´m trying to set some values within a object using forEach lambda:

var row = {title: "", attribute:"", width: ""};
list.forEach( list =>
row.title = list.label |
row.attribute = list.label |
row.width = "300px"
);


Works fine only with a statement
row.title = list.label
when I add the rest of parameters does not work fine.

What is the right syntax?

Answer

Try:

 var row = {title: "", attribute:"", width: ""};
 list.forEach( list => {
                 row.title = list.label;
                 row.attribute = list.label;
                 row.width = "300px"    
              });

Notice the curly braces.

Comments