I would like to get result like
arr=['A','B','C','D']
from the object like below.
var obj = {
obj1: 'A',
obj2: [ 'B', 'C', 'D' ] }
How to reach out to concatenate to array?
If someone has opinion, please let me know.
Thanks
You can get the values using Object.values() and to get them in one array you can use Array.prototype.flat():
var obj = {
obj1: 'A',
obj2: ['B', 'C', 'D']
}
var arr = Object.values(obj).flat()
console.log(arr)
You can make use of Object.values and spread it into a single array with Array.prototype.concat since Array.prototype.flat is not supported in older browsers
var obj = {
obj1: 'A',
obj2: ['B', 'C', 'D']
}
var vals = [].concat(...Object.values(obj))
console.log(vals)
... in front of Object? thanks