Skip to main content

All Questions

2 votes
1 answer
39 views

How to assign object with properties to property of an object using reduce

I have a data like this const dataSet = [ { 'Transactions.productRef': 'SomeRef/123', 'Transactions.itemCount': 25, 'Transactions.revenue': 1000, }, { 'Transactions....
Milos's user avatar
  • 619
-1 votes
2 answers
110 views

Edit a specific object property keeping the same object structure

Let's say I have this object: a = { key1: { name: 'a', import: 1234.7896, discount: 122.34553 } key2: { name: 'b' import: 8976.09998, discount: 12.890999 } } and I ...
palnic's user avatar
  • 416
1 vote
2 answers
2k views

Create an object with key-value pairs from an array

Having this input array: const myArray = [{value: "test"}, {value: "abc"}, {value: "xyz"}]; the desired result is this: result = { "value1": "test", &...
Jean Pierre's user avatar
0 votes
2 answers
94 views

How to group array of objects by common property and put other properties together

I have an array of objects like this const statuses = [ {time: '21/1/1990', 'Status.sold': 8848}, {time: '21/1/1990', 'Status.reserved': 8804}, {time: '21/1/1991', 'Status.reserved': 8756}, {...
Milos's user avatar
  • 619
1 vote
3 answers
709 views

How to subtract object values and add result to a new property

I have an array of objects like this const arr = [ {time: '21/1/1998', sold: 8848}, {time: '21/1/1997', sold: 8804}, {time: '21/1/1996', sold: 8756}, {time: '21/1/1995', sold: 8732}, {time: '...
Milos's user avatar
  • 619
0 votes
3 answers
103 views

Using reduce and sort together (JavaScript)

I have an array of objects (groceryArray) that I would like to organize into an object by the groupId property (object keys) and finally sort these keys by the groupDisplayOrder property. See ...
Michael's user avatar
  • 433
2 votes
3 answers
724 views

Restructure array of objects then grouping objects

So I have found a solution, but I am still learning and feel like my solution is too long. It does not use all of ES6 and could be better. I would love any feedback and/or suggestions. The data looks ...
Amelia W's user avatar
  • 101
0 votes
4 answers
115 views

Group array of object by key - javascript

Before anything, I did look for the other answers on the internet but I still can't get it to work and I don't know why So, I have an array with objects: array =[ { "name":"...
user9875's user avatar
  • 133
0 votes
1 answer
69 views

Why item inserted in object? [closed]

I found an groupby implementation in ES6 for grouping this data object: const pets = [ {type:"Dog", name:"Spot"}, {type:"Cat", name:"Tiger"}, {type:&...
Michael's user avatar
  • 27
2 votes
2 answers
516 views

JavaScript: Reduce an array to nested objects

So suppose my array looks like this: let langArr = [ ["python", "blue"] ,["python", "blue"] ,["c++", "red"] ,["java", "yellow"] ,["javascript", "lime"] ,["shell", "green"] ...
m00's user avatar
  • 317
2 votes
1 answer
107 views

Flip key value pair on 1 lvl depth

I have object: const pairs = { A: { D: [1, 2, 3] }, B: { D: [3, 2, 1] }, C: { D: [4, 3, 2, 1], B: [0, 1, 2, 3] } }; How can I get it fliped? const fliped = { D: { A: [1, 2, 3], B: ...
giaosl's user avatar
  • 107
4 votes
6 answers
235 views

JS reduce - sum only array lengths in object

I have the following data structure: const arr = [ {key: 0, x: [], y: []}, {key: 0, x: [], y: []} ] I want to check if all arrays are empty, I have how can I do this using reduce? My ...
mtwallet's user avatar
  • 5,050
-2 votes
4 answers
103 views

How to get some props of list array object by using reduce

I have list array object like: let arr = [ { a: 1, b: 2, c: 3, d: 4 }, { a: 2, b: 3, c: 4, d: 5 }, { a: 5, b: 6, c: 7, d: 8 } ] and after using reduce() // get props **b, c** let ...
hyphens2's user avatar
  • 166
1 vote
4 answers
104 views

Convert array of objects to array of arrays (by attribute)

I want transform my array to array of arrays by attribute "icon". const array = [ { icon: true }, { icon: false }, { icon: false }, { icon: true }, { icon: false } ] I need: [[{icon: ...
user3468894's user avatar
0 votes
0 answers
349 views

Redux reducer - object destructuring does not work

I'm struggling with object destructuring using this syntax: const { [key]:value, ...allNewUserMsgs } = allUserMsgs where (example) allUserMsgs = { 0 : {number: 0, text: "Those kumquats are nothing ...
wawraf's user avatar
  • 23

15 30 50 per page