• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

187
Views
Lodash + Json: Split and display grouped data into a JSON file(Help)

I'm learning lodash functions and I've been trying to find a method to split a data set and group using lodash. Any immediate help would be highly appreciated.

The dataset is as follows

car:brand:ford,
car:brand:audi,
car:brand:volvo,
car:brand:toyota, lexus,

phone:brand:samsung,
phone:brand:apple, iPhone, xr,
phone:brand:huawei,
phone:brand:nokia, lumia,

And the expected out come with split and grouped is as follows

"car:brand": [ 

    "ford",,
    "audi",
    "volvo",
    "toyota, lexus",
],

"phone:brand": [ 

    "samsung",
    "apple, iPhone, xr",
    "huawei",
    "nokia, lumia",
],

So far I've come up with this part, and I'm stuck. I would like to learn how to do it using lodash _.split mainly

let brand = 'dataset'
let arr = _.chain(brand)
.split('car:brand:')
.join(',')
.split('phone:brand:')
.join(',')
.split(',')
.chunk(2)
.value();
console.log(arr);

This is not successful, is there an efficient way to split and group the data set using lodash functions? Any help would be much appreciated.

Console output

(8) [Array(2), Array(2), Array(2), Array(2), Array(2), Array(2), Array(2), Array(2)]
0: (2) ["", "ford"]
1: (2) ["", "audi"]
2: (2) ["", "volvo"]
3: (2) ["", "toyota"]
4: (2) ["lexus", ""]
5: (2) ["samsung", ""]
6: (2) ["apple", " iPhone"]
7: (2) [" xr", ""]
length: 8

When expanded

0: Array(2)
0: ""
1: "ford"
length: 2
[[Prototype]]: Array(0)
almost 3 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error