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]]"
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);
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);
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);