[Solved] Converting array into a JS Object


You could iterate the strings, split the values and take the first item as key and join all other values (if splitted) for a new object.

At the end create a single object.

var data = ["model:B250W,C300W4,E300W4,GLA250W4", "class:E", "exteriorColor:BLK", "interiorColor:BGE", "price:30000,115000", "year:2018", "bodyStyle:SDN,CPE,SUV"],
    object = Object.assign(
        ...data.map(s => (([k, ...v]) => ({ [k]: v.join(':') }))(s.split(':')))
    );
    
console.log(object);

0

solved Converting array into a JS Object