Home > Software engineering >  splitting a dynamic string to store in separate variable
splitting a dynamic string to store in separate variable

Time:11-16

I have a dynamic string like below one getting from server.it may be more than 2.

[{text :'AC Maintenance today ', value:16.00, color: '#DEE3E8'},{text :'test3', value:150.00, color: '#5A0C55'}]

How to get each values in a separate js variable. for eg

var text = ["AC Maintenance today","test3"];
var value = [16.00,150.00];
var color = ["#DEE3E8","#5A0C55"]

CodePudding user response:

var values = [{text :'AC Maintenance today ', value:16.00, color: '#DEE3E8'},{text :'test3', value:150.00, color: '#5A0C55'}]

const text = values.map((v) => v.text)
const value= values.map((v) => v.value)
const color= values.map((v) => v.color)
  • Related