I want to extract the name and rate from each element of the array below, and turn them into an array of object
[
'BTCUSDT Perpetualt8ht05:14:44t0.0100%t0.01%t0.3000% / -0.3000%t0.3000% / -0.3000%',
'ETHUSDT Perpetualt8ht05:14:44t0.0100%t0.01%t0.3750% / -0.3750%t0.3750% / -0.3750%',
'BCHUSDT Perpetualt8ht05:14:44t-0.0135%t0.01%t0.3750% / -0.3750%t0.3750% / -0.3750%'
]
The following is what i expect to get:
[
{"name":BTCUSDT, "rate":0.01%},
{"name":ETHUSDT,"rate":0.01%},
{"name":BCHUSDT,"rate":0.01%},
]
Appreciate for any suggestions.
3
Answers
Try using
arr.reduce()
You can use a combination of array mapping and string splitting to achieve this: