I would like to return the parameter word
of my arrow function as the property of the object key. But the object returned contains the property "word"
instead.
lines = ["first row","second row","third row"]
let newLines = lines.map((item, index)=> {
let wordsPerLines = item.split("\s");
return wordsPerLines.map(word => ({ word : index}))
}
);
console.log(newLines);
This is the output:
[
[
{
"word": 0
},
{
"word": 0
}
],
[
{
"word": 1
},
{
"word": 1
}
],
[
{
"word": 2
}
]
]
I would like to have instead this output :
[
[
{
"first": 0
},
{
"row": 0
}
],
[
{
"second": 1
},
{
"row": 1
}
],
[
{
"third": 2
},
{
"row": 2
}
]
]