I have string like
var t = 'red: 5, purple: 7, fuchsia: 10, green: 8';
I want to make array like
a = ['red', 'purple', 'fuchsia', 'green'];
b = [ 5, 7, 10, 8]
Please help me
>Solution :
Sample solution:
const t = 'red: 5, purple: 7, fuchsia: 10, green: 8';
const tarr = t.split(', ');
const a = [];
const b = [];
for (const item of tarr) {
const [k, v] = item.split(': ');
a.push(k);
b.push(~~v); // '~~' is a shortcut to convert string value to number
}
console.log(a, b);