Skip to main content

All Questions

3 votes
2 answers
2k views

Add a new key and value to a Javascript object from an existing array of values

I have an existing array of ids that I'm trying to iterate over to add each as an id: key to an existing array of objects. I have tried a number of different loops (for, for in, map, forEach), but I ...
i-am-niall's user avatar
0 votes
2 answers
895 views

How to turn 2 arrays into an object with key value pairs

I have an object which contains 2 objects with properties: const objects = { Battery: { batteryDetailsKey: ['serial_no', 'type', 'part_no'], batteryDetailsVal: [ 'HJ3CA19347410218LJ98 ...
Jim41Mavs's user avatar
  • 552
-1 votes
5 answers
651 views

How can I loop over a multi level JSON object and create a new Javascript object from one of it's key and values

I have a JSON object that looks like the following { "venue": { "time1": [ { "Status": "Available" }, ...
i-am-niall's user avatar
0 votes
3 answers
153 views

Efficient way to get top count of an option in an array of objects

I have an array of objects like this, [ { user: 'A', answers: [ { id: 1, score: 3, }, { id: 2, score: 1, }, ... ] }, { ...
Kelvin Zhao's user avatar
  • 2,403
1 vote
5 answers
83 views

push value duplicate into new array

I have array of object like this const data = [ { name: "John", transaction: "10/10/2010", item: "Bag" }, { name: "Steven", ...
Weq Iou's user avatar
  • 233
1 vote
1 answer
186 views

Javascript ES6 better way to loop object and match with multiple nested object and return id

I have it done but I think is not the best. I want to find out a better way (ES6) to loop multiple nested objects and met a condition and return id like below outcome (with and without) I have two ...
Sameul.T's user avatar
  • 309
1 vote
2 answers
23 views

replacing key object for the array values

Im having a problem with replacing keys in object let headers = ['title1', 'title2', 'title3'] let obj = { 0: ['name1', 'name2, 'name3], 1: ['example1', 'example2, 'example3], 2: ['xx', '...
kasia's user avatar
  • 298
-2 votes
1 answer
393 views

Function looping through object keys throws undefined

I'm trying to iterate through an Inventory object when the sale fucntion is called, and it should check the article requested and its amount. Always updating the inventory when a sale is made, and if ...
Mat Mol's user avatar
  • 83
-1 votes
2 answers
315 views

How do I push a field of an object into another array of object

I know how to operate on array of objects but never had the necessity to populate an array data into another. I need to populate firstname + lastname field into name field of birth array let birth = [...
Ovy MC's user avatar
  • 89
1 vote
3 answers
809 views

Why this object destructuring in for-of loop doesn't work?

Basically the following code doesn't work and I don't understand why. in the nested loop, I have a variable called "children" that is an array containing objects with fields called children (like in a ...
Baptiste Mazin's user avatar
2 votes
3 answers
121 views

How to create a new array of objects form object without duplicates ? (ES6)

I would like to create an array of all "department" from the "users" array without duplicate in ES6. I've tried with forEach, reduce, filter, without success... Users array: let users = [{ ...
Vincent Ducorps's user avatar
0 votes
4 answers
62 views

Convert values in array of objects [duplicate]

I have an array of objects with String values that I want to convert to Date, but I'm getting the following error: Uncaught SyntaxError: Unexpected token : How should I correctly do this ...
Fellow Stranger's user avatar
1 vote
2 answers
112 views

ES6 implementation of this function?

This function loops through an array of objects, and takes an object as a second parameter. It will loop through the array of objects replacing it with the object passed in as the second argument if ...
Guven8's user avatar
  • 51