My goal is to have the parameter word
of my arrow function return as the property of the object key. However, the object returned currently contains the property "word"
.
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 current output:
[
[
{
"word": 0
},
{
"word": 0
}
],
[
{
"word": 1
},
{
"word": 1
}
],
[
{
"word": 2
}
]
]
I am aiming for this desired output instead:
[
[
{
"first": 0
},
{
"row": 0
}
],
[
{
"second": 1
},
{
"row": 1
}
],
[
{
"third": 2
},
{
"row": 2
}
]
]