getting nested data from JSON array object

Saurabh

this is what my data looks like

 { _id: 5a114dede58f4a05cb135d96,

   messages: [
        { 
         id: 5a114c66e58f4a05cb135d8c,

         User: 'developer2', 

        _id: 5a114e26e58f4a05cb135d9b,

          texts: [{
                   _id: 5a114e26e58f4a05cb135d9d,
                   message: 'hii',
                   username: 'ruby' 
                  },
                  { 
                   _id: 5a114e40e58f4a05cb135d9e,
                   message: 'es',
                   username: 'shan' 
                  }
                                         ] } ]
                  }
     }

how do I extract all data from texts, I'd used this but this not returning any thing

  <% texts.messages.texts.forEach(function(text){ %>


  <p><%=text.message%></p>
   <p><%=text.username%></p>

   <% })  %>

**Edit:when i just printing

<%=texts%>

**

{ _id: 5a114dede58f4a05cb135d96,  
    messages: [ { id: 
     5a114c66e58f4a05cb135d8c,
       User: 'developer2', _id: 
     5a114e26e58f4a05cb135d9b,
      texts: [Array] } ] 
}

I'm not able to see data inside texts unless I print this

<%=texts.messages%>

*this is what i get after writing texts.messages *

 {
texts: [{
                   _id: 5a114e26e58f4a05cb135d9d,
                   message: 'hii',
                   username: 'ruby' 
                  },
                  { 
                   _id: 5a114e40e58f4a05cb135d9e,
                   message: 'es',
                   username: 'shan' 
                  }
                                         ] } ]
                  }
     }

My route to transfer data to ejs

User.findOne({username:req.user.username},{messages:
      { $elemMatch: { 
      User:req.params.username} }},
      function(err,data){
         if (err) {
            throw err;
           } else {
            res.render("chat",{texts:data,user:founduser});
        }
       }) 

what am I missing here ?

Mustafa Mamun
<% texts.messages.forEach(function(message){
message.texts.forEach(function(text){ %>


<p><%=text.message%></p>
<p><%=text.username%></p>

<% }}))  %>

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 json data from a nested array

From Dev

Getting data from complex nested JSON object (using PHP)

From Dev

Getting data from JSON Object

From Dev

KnockoutJS - Getting ViewModel data from a Nested Object

From Dev

Getting data from nested JSON object !!WITH ID'S!! using angular GET

From Dev

Getting data from an array in JSON data with Swift

From Dev

json object from javascript nested array

From Dev

json decode - getting single array from object?

From Dev

Getting null data from a JSON object

From Dev

Getting the data from json object in javascript

From Dev

Error in getting data from JSON Object

From Dev

Getting child data from a JSON object in angular

From Dev

Getting Value From Json Data Inside Array

From Dev

Getting data part from JSON Array

From Dev

In javascript, how do I create a nested array or object from json data?

From Dev

Having trouble getting nested ojects from json array in python

From Dev

jquery $.each nested in another $each. getting data from a JSON

From Dev

Cannot getting data from external nested json file form jquery

From Dev

Issue in getting the required data from nested json and store it in a pandas dataframe?

From Dev

Getting nested object array values into another array

From Dev

Getting nested object array values into another array

From Dev

How to parse nested Json Object inside Array Data in Ios

From Dev

Getting particular object from nested complex object

From Dev

GO - Get an array of attribute values from a nested JSON object

From Dev

Removing object from nested json array jquery (splice)

From Dev

How to generate a nested array of objects from an source json object

From Dev

Getting data from array

From Dev

Nested loop to show data from JSON array in php

From Dev

Saving data from a nested JSON decoded array into a Laravel DB

Related Related

  1. 1

    Getting json data from a nested array

  2. 2

    Getting data from complex nested JSON object (using PHP)

  3. 3

    Getting data from JSON Object

  4. 4

    KnockoutJS - Getting ViewModel data from a Nested Object

  5. 5

    Getting data from nested JSON object !!WITH ID'S!! using angular GET

  6. 6

    Getting data from an array in JSON data with Swift

  7. 7

    json object from javascript nested array

  8. 8

    json decode - getting single array from object?

  9. 9

    Getting null data from a JSON object

  10. 10

    Getting the data from json object in javascript

  11. 11

    Error in getting data from JSON Object

  12. 12

    Getting child data from a JSON object in angular

  13. 13

    Getting Value From Json Data Inside Array

  14. 14

    Getting data part from JSON Array

  15. 15

    In javascript, how do I create a nested array or object from json data?

  16. 16

    Having trouble getting nested ojects from json array in python

  17. 17

    jquery $.each nested in another $each. getting data from a JSON

  18. 18

    Cannot getting data from external nested json file form jquery

  19. 19

    Issue in getting the required data from nested json and store it in a pandas dataframe?

  20. 20

    Getting nested object array values into another array

  21. 21

    Getting nested object array values into another array

  22. 22

    How to parse nested Json Object inside Array Data in Ios

  23. 23

    Getting particular object from nested complex object

  24. 24

    GO - Get an array of attribute values from a nested JSON object

  25. 25

    Removing object from nested json array jquery (splice)

  26. 26

    How to generate a nested array of objects from an source json object

  27. 27

    Getting data from array

  28. 28

    Nested loop to show data from JSON array in php

  29. 29

    Saving data from a nested JSON decoded array into a Laravel DB

HotTag

Archive