javascript - JS Combine array values into one single value -
i have object
a = {key:'animals', options: ['dog','cat','penguin']}
how can simplify this:
b = ['animals','dogcatpenguin']
like
var = { key: 'animals', options: ['dog','cat','penguin'] }; var key, b = []; (key in a) { b.push(array.isarray(a[key]) ? a[key].join('') : a[key]); } console.log(b);
or can use object.keys
.map
var = { key: 'animals', options: ['dog','cat','penguin'] }; var b = object.keys(a).map(function (key) { return array.isarray(a[key]) ? a[key].join('') : a[key]; }); console.log(b);
Comments
Post a Comment