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
2
votes
2 answers

Converting given structure two-dimensional array into array of nested objects

I have a sorted two-dimensional array as an input. I need to get an array of nested objects in the same structure as shown below. How do I get an expected output? input = [ ["1", "2", "3", "4", "5", "6", "7", "8"], ["1", "2", "3", "4", "5", "6",…
2
votes
2 answers

Sorting nested objects

I am trying to sort object of objects obj in javascript on the basis of cummulativeSite in descending order through object.keys but it is not getting sorted.Please suggest a good approach or a method for the same to sort this. var obj={ B.E:{ …
2
votes
4 answers

map nested array in javascript

I have a nested array of objects like this: let data = [ { id: 1, title: "Abc", children: [ { id: 2, title: "Type 2", children: [ { id:…
Amir Shahbabaie
  • 1,352
  • 2
  • 14
  • 33
1
vote
1 answer

How to get callback when subset of nested properties change in this system?

Say I have a "type" like this: { a: { b: { c: { d: string e: boolean } }, x: string y: number z: string } } At each object node, I want to get notified if all of the children are "resolved" to a…
Lance
  • 75,200
  • 93
  • 289
  • 503
1
vote
1 answer

How to narrow a variable from a string to a key of a nested object in a large object with Discriminated unions

I'm working with a double-nested JSON object in typescript, and have been banging my head against a wall when I try to narrow a string down to a key for the first nested string. Narrowing a string to a key for the main object is trivial, and if…
1
vote
1 answer

Find how many times each response was given for each question

SURVEY DATA Each object is a survey which can have up to 10 questions and up to 5 different responses. const allSubmittedSurveysData:{}[] = [ { surveyGUID:'1234', q1ID: '0001', q1Response:'Very…
1
vote
1 answer

Select objects based on value of variable in nested objects using jq

My question is very similar to one found here - I have the following JSON { "FOO": { "id": "23432423", "Result": { "Status": "SUCCESS", "Reason": "" } }, "BAR": { "id": "45345535", "Result": { "Status":…
Arvind
  • 11
  • 2
1
vote
0 answers

update nested object fields, and return new object react. (recursion)

hi everyone, i got an issue im stuck at. i got a nested object, (for the sake of simplicity, i've updated the object to be much less complicated) here is what it looks like: export const customerDraft = { _id: "6368dab51482da28ba792712", …
ikkako
  • 29
  • 9
1
vote
3 answers

Working with nested objects. What do 'car', 'inside', and 'outside' specify here

const myStorage = { 'car': { 'inside': { 'glove box': 'maps', 'passenger seat': 'crumbs' }, 'outside': { 'trunk': 'jack' …
Codewell
  • 13
  • 6
1
vote
1 answer

Nested Object in React and display in table

I am having trouble iterating through my object. export default function UserProfile(props) { // props.user has Object{social:Object{email:{},.....}} const form = useForm({ // Mantine form initialValues: { social: { …
1
vote
2 answers

Update deeply nested state object in redux without spread operator

I've been breaking my head for a week or something with this !! My redux state looks similar to this { data: { chunk_1: { deep: { message: "Hi" } }, chunk_2: { something: { …
1
vote
7 answers

Return all nested objects with specific keys

I have an array of objects in Javascript: [ {a: 1, b: 2, c: 4}, {d: 10, a: 9, r: 2}, {c: 5, e: 2, j: 41} ] I would like to return an array of all the objects that have the key name c by using the key name for the lookup. What is the best way to…
1
vote
4 answers

Function to update any value by key in nested object

I want to write a function that takes a keyName, newValue, and object, and returns the object with the updated key/value pair. For example... Given this data: const data = { token: { id: "abcxyz", year: "2022" }, order_data: { …
JBrown
  • 825
  • 6
  • 22
1
vote
2 answers

Javascript Building a Nested Object (tree) from an very weird array Debugging

I could really use some help Debugging a problem. Im trying to build a nested object (tree) from a very unusual array im getting from a backend (dont have access to the BE so i have to work with what i got). I’ve gotten 95 percent of it done but im…
LuisPM
  • 13
  • 5
1
vote
2 answers

angular reading null value for existing nested object

I have a fully populated object coming through from my server to my angular service. in postman I can see the entire object is there correctly. even in the angular component that calls the service, when I JSON.stringify the object and print it to…
1 2
3
17 18