Questions tagged [nested-object]

Objects are composite data types which are built from primitives and other objects. An object’s building blocks are commonly referred to as its "fields" or "properties" comprising of `key -> value` pairs. A nested object is basically a data structure where an object refers to other objects, i.e. an object's values is another object or another set of objects. Such nested structures can be accessed by consecutively applying dot notation or bracket notation.

Objects are composite data types which are built from primitives and other objects. An object’s building blocks are commonly referred to as its "fields" or "properties" comprising of key -> value pairs.

A nested object is basically a data structure where an object refers to other objects, i.e. an object's values is another object or another set of objects.

A nested object structure can be accessed by chaining dot notations or bracket notations. For example, in the following, if we want to access the first a property from nestedObject1:

obj = {
    a: "1",
    nestedObject1: [{
        a: "2",
    }, {
        a: "3",
    }]
};

Using dot notation, we can access that property like this:

obj.nestedObject1[0].a

//will return the value "2" of the first property `a` from nestedObject1

Using bracket notation, we can access that property like this:

obj["nestedObject1"][0]["a"]

//will return the value "2" of the first property `a` from nestedObject1
267 questions
16
votes
2 answers

Destructuring Nested objects in javascript | Destructure second level parent and child Objects

I need to destructure and get values of title, child, childTitle from this object const obj1 = { title : 'foo', child : { title2 : 'bar' } } let {title, child} = obj1; console.log(title) // 'foo' console.log(child) // { title :…
4
votes
8 answers

loop through nested object javascript

I am trying to loop through a following nested object and get an output as below: const preference = { "ethnicity": { "value": "Newar", "rank": 1 }, "occupation": { "value": "Banker", "rank": 2 } } I…
Azima
  • 3,835
  • 15
  • 49
  • 95
3
votes
2 answers

Find by key get value and replace by second json value in nested json object

I have an json object(firstObj) It can be nested and I have an second object containing key/value pair. I want to replace the second object's value by first one by matching value and do it's operation. let firstObj = { amount_money: { …
supunbatagoda
  • 73
  • 1
  • 10
3
votes
3 answers

Javascript check all values of object and it's nested object

Hi i'm currently stuck with this problem of checking an object that has another nested object if all value in it is null or 0 My object is as follow: { "city":0, "road":{ "max":null, "min":null }, "size":{ "max":null, …
Linh Nguyen
  • 3,452
  • 4
  • 23
  • 67
3
votes
2 answers

What is the most efficient way of rendering a n-level nested object in React JS?

I have a data coming from API as follows - { "expression": [ "a", "b" ], "groups": [ { "expression": [ ], "groups": [ { "expression": [ "c", "d" ], …
3
votes
1 answer

Mongoose - Query deeply nested Objects

I currently have a problem where I have to update entries in a deeply nested Document. Now to simplify my problem I have this example. Let's assume I store cars in my MongoDB. A Document would look like this { Make: "BMW", Model: "3Series", …
relief.melone
  • 3,042
  • 1
  • 28
  • 57
2
votes
3 answers

computationally efficient way to manipulate the levels of large deeply-nested objects?

I have a list of lists of vectors (non a typo, re-confirming that it is infact a list of lists of vectors) that is 76 million in length. So, there is a list of 76 million items where each item is a list of two vectors. All the vectors are, of…
Sudoh
  • 313
  • 2
  • 11
2
votes
1 answer

JS sort() doesn't work as expected on nested objects

I have an array of objects like below, and I would like to sort the array by value of each object. const arr = [ { 0: "id1", 1: { title: "object1", value: 200 } }, …
Piotr
  • 21
  • 2
2
votes
1 answer

how to make a generic sorting function in typescript?

I have an HTML table which is filled with data from an array of objects. The columns of this table are object properties. I want the data to be sorted when any column header is clicked. However I'm finding it difficult to write a generic sorting…
ma_po
  • 23
  • 4
2
votes
2 answers

Recursive javascript function that converts nested object keys to string and store all keys in arrray

I am trying to write a javascript recursive function that receives one parameter - nested JSON object. The function goes through the potentially infinitely nested object and converts all the keys (property names) to a string that is stored in array.…
2
votes
2 answers

How to type nested objects using Object.keys()?

I am using the nested object and trying to get to the properties using Object.keys() and forEach(). The problem is when I want to get to the nested keys filteringState[item][el]. How to type function like this? interface InitialStateTypes { …
BartD
  • 53
  • 5
2
votes
1 answer

How to push an object coming from postman as a number(validationError)?

My main problem is I cannot push quantity to its respective object. I am posting data in JSON format in postman like this: "productId":"621256596fc0c0ef66bc99ca", "quantity":10 my schema is: userOrders:[ { …
2
votes
3 answers

Nested Object Loop in JS

I'm trying to add a series of values to a nested object, having some trouble with the loop in the following code. Any help would be really appreciated. let settings = {}; function write(id, values) { if(!settings[id]) settings[id] = {}; …
Mike
  • 23
  • 2
2
votes
1 answer

Get as many nested Records in returnType as the arguments passed to the function

What I am trying to achieve is typing a deeply nested ReturnType of a function, based on the number of arguments provided in the "rest" argument. For example, if we have: getFormattedDates( dates: Date[], ...rest: string[] // ['AAA', 'BBB',…
2
votes
1 answer

how to update nested object with useReducer in React?

How do I update the courseName using this use reducer? error: "cannot create property on courseName on string "science". I am assuming Im not accessing it correctly? I have been using useState but i want to learn useReducer for more complex…
lache
  • 608
  • 2
  • 12
  • 29
1
2 3
17 18