Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

194
Views
how to create an object from an array and calculate values in a new object?

I have an array where each index with the same name should be counted in the object. Please check the example and result below. I'm trying to figure out a few things:

  1. how to create two new objects "viktor" and "kate" inside the object ?
  2. how to provide a calculation for each key if they are the same: "apple", "grape", "orange", "apple" and "banana" ?
const obj = {
  viktor: ["apple", "grape", "orange", "apple", "banana"],
  kate: ["grape", "orange", "apple", "grape", "banana"]
};

function calc(a) {
}

console.log(calc(obj));

// result of calc method should be equal to
// {
//   viktor: {
//     apple: 2,
//     grape: 1,
//     orange: 1,
//     banana: 1
//   },
//   kate: {
//     apple: 1,
//     grape: 2,
//     orange: 1,
//     banana: 1
//   }
// }
about 4 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 Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!