Now I have array like this
let arr = [{
name: 'Tony', age: 17, love: [1, 2, 4]
}, {
name: 'David', age: 12, love: [6, 6, 6]
}, {
name: 'John', age: 10, love: [0, 0, 0]
}]
And I want to map this array and get result
const a1 = arr.map(man => {
if(man.name === 'Tony') {
for(let i = 0; i < man.love.length; i++) {
return man.love[i]
}
}
else {
return man.name
}
})
The result I Want is [ 1, 2, 4, 'David', 'John' ]
.
But I got [ 1, 'David', 'John' ]
How can I achieve that? Thanks in advanced!