Skip to content
Advertisement

Need to separate particular String from array in javascript

I have a output like this

Output :

[{service: 'xdc'},{service: 'cddc'}, {service:
'cdcd'},{service: 'cddc'}]

I need to convert like this

output : [xdc,cddc,cdcd,cddc]

Advertisement

Answer

You can use Array.prototype.map() combined with Destructuring assignment

Code:

const output = [{service: 'xdc'},{service: 'cddc'}, {service: 'cdcd'},{service: 'cddc'}]

const result = output.map(({ service }) => service)

console.log(result)
Advertisement