Getting Parent Object, from nested value

Lutfor

what javascript code could you use to return person1 object providing id parameter 1 or person2 object providing id parameter 2?

  {
        person1: 
        {
            id: 1,
            name: 'john'
        },
       person2: 
        {
            id: 2,
            name: 'doe'
        }
    }
amanuel2

You can just loop through them using foreach.. Lets say we had your object here:

var obj = {
  person1: {
    id: 1,
    name: 'john'
  },
  person2: {
    id: 2,
    name: 'doe'
  }
}

Then you just loop and find the one.. so lets say you had the ID.

var ID = 2;
for (var i in obj) {
   if(obj[i].id == ID){
    result = obj[i]; //this is person2...
   }
}

I Hope this is what you are asking for.. your question wasnt very clear.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Getting the highest value excluding a certain value from a nested object property

From Dev

nested ListView not getting values from parent listview

From Dev

Getting particular object from nested complex object

From Dev

extJs access a parent function from nested object

From Dev

Getting Parent node from Json object with Jquery

From Dev

Getting value from a collection object

From Dev

Getting value from object in javascript

From Dev

php getting value from object

From Dev

Powershell - Getting multiple values from a nested object

From Dev

KnockoutJS - Getting ViewModel data from a Nested Object

From Dev

getting nested data from JSON array object

From Dev

Getting a value from parent activity returns null

From Dev

Getting json value from nested response

From Dev

Laravel Blade: Getting access to a variable in a nested partial from a parent view

From Dev

Getting the type of another nested class from the same "parent" class

From Dev

Nested View not getting data from parent controller in Laravel 5.1

From Dev

Nested View not getting data from parent controller in Laravel 5.1

From Dev

Parent value as sum of all children values within nested javascript object

From Dev

DataRowView object getting null value at time of getting value from DataGrid

From Dev

Object from nested hash depending on key value

From Dev

How to get the key value from nested object

From Dev

Adding up a value from a nested object

From Dev

ExpressJS Fetching value from nested JSON Object

From Dev

Get min value from a nested json object

From Dev

JavaScript get value from nested object

From Java

Getting key with the highest value from object

From Dev

Getting Map value from JAXB Response Object

From Dev

Getting checkbox value from json object

From Dev

perl: getting a value from a function of the object

Related Related

  1. 1

    Getting the highest value excluding a certain value from a nested object property

  2. 2

    nested ListView not getting values from parent listview

  3. 3

    Getting particular object from nested complex object

  4. 4

    extJs access a parent function from nested object

  5. 5

    Getting Parent node from Json object with Jquery

  6. 6

    Getting value from a collection object

  7. 7

    Getting value from object in javascript

  8. 8

    php getting value from object

  9. 9

    Powershell - Getting multiple values from a nested object

  10. 10

    KnockoutJS - Getting ViewModel data from a Nested Object

  11. 11

    getting nested data from JSON array object

  12. 12

    Getting a value from parent activity returns null

  13. 13

    Getting json value from nested response

  14. 14

    Laravel Blade: Getting access to a variable in a nested partial from a parent view

  15. 15

    Getting the type of another nested class from the same "parent" class

  16. 16

    Nested View not getting data from parent controller in Laravel 5.1

  17. 17

    Nested View not getting data from parent controller in Laravel 5.1

  18. 18

    Parent value as sum of all children values within nested javascript object

  19. 19

    DataRowView object getting null value at time of getting value from DataGrid

  20. 20

    Object from nested hash depending on key value

  21. 21

    How to get the key value from nested object

  22. 22

    Adding up a value from a nested object

  23. 23

    ExpressJS Fetching value from nested JSON Object

  24. 24

    Get min value from a nested json object

  25. 25

    JavaScript get value from nested object

  26. 26

    Getting key with the highest value from object

  27. 27

    Getting Map value from JAXB Response Object

  28. 28

    Getting checkbox value from json object

  29. 29

    perl: getting a value from a function of the object

HotTag

Archive