92
rated 0 times
[
99]
[
7]
/ answers: 1 / hits: 16789
/ 7 Years ago, wed, january 3, 2018, 12:00:00
Using lodash I need to convert an array of object to the array of string.
Original array,
const tags = [{
display: tag1,
value: tag1
}, {
display: tag2,
value: tag2
}]
Expected result,
const tags = [tag1, tag2]
I tried this way,
const data = [{
display: tag1,
value: tag1
}, {
display: tag2,
value: tag2
}]
const result = _(data)
.flatMap(_.values)
.map((item) => { if (typeof item === 'string') { return item; } else { return; } })
.value()
console.log('result', result);
More From » arrays