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

76
Views
make a dimensional array from object

I get this data from the backend

let procedure_word_count = [{"slug":"new","name":"New","count":1},{"slug":"no-need","name":"No Need","count":2},{"slug":"why","name":"Why","count":2}]

My goal is to create a dimensional array that extracts the name and count from the "procedure_word_count"

let newArray = "[['New', 1], ['No Need', 2], ['Why', 2]]"
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You can always map it and create an array from the object:

let example = [
  {"slug":"new","name":"New","count":1},
  {"slug":"no-need","name":"No Need","count":2},
  {"slug":"why","name":"Why","count":2}
];

let result = example.map((item) => [item.name, item.count]);
console.log(result);

about 4 years ago · Juan Pablo Isaza Report

0

The map method creates a new array with the results of calling a function for every array element so it's a classic for this one. for each iteration the function will return an array containing the selected keys values.

const arr = [{"slug":"new","name":"New","count":1},{"slug":"no-need","name":"No Need","count":2},{"slug":"why","name":"Why","count":2}];

const res = arr.map(x => [x.name, x.count]);
console.log(res);

about 4 years ago · Juan Pablo Isaza Report

0

The JSON you retrieve from the server can be iterated over using the .map() method.

.map() iterates over each element and builds an array.. The function returns whatever you want - in this case the name and count properties.

const input = [{"slug":"new","name":"New","count":1},{"slug":"no-need","name":"No Need","count":2},{"slug":"why","name":"Why","count":2}];

const output = input.map(o=>[o.name,o.count]);

console.log(output);

about 4 years ago · Juan Pablo Isaza Report
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!