Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8733905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:44:32+00:00 2026-06-13T09:44:32+00:00

i want to pass an array of objects from mongodb to the client… this

  • 0

i want to pass an array of objects from mongodb to the client…

this is the object

var objeto_img=
                            {
                                name:'name of the file',
                                image:'image.jpg url',
                                title:'title of the image',
                                caption:'descripcion of the image',
                                link:"#",
                            };

in some profiles the are many images so the is an array of objects like this

[var objeto_img=
                            {
                                name:'name of the file',
                                image:'image.jpg url',
                                title:'title of the image',
                                caption:'descripcion of the image',
                                link:"#",
                            },var objeto_img=
                            {
                                name:'name of the file',
                                image:'image.jpg url',
                                title:'title of the image',
                                caption:'descripcion of the image',
                                link:"#",
                            },var objeto_img=
                            {
                                name:'name of the file',
                                image:'image.jpg url',
                                title:'title of the image',
                                caption:'descripcion of the image',
                                link:"#",
                            };]

this is the server code

res.render('index/perfil_publicacion_contenido',
    {
        datos:datosRecibidos
    })

datosRecibidos is an array of objects from mongodb

and im trying to put in a variable inside jade

input(type='hidden',id='imagenes',value=datos.img)

but when i try to get the objects

var fotos=$('#imagenes1').val();
            for(foto in fotos)
            {
                console.log(fotos[foto].image)
                console.log(fotos[foto].name)
                console.log(fotos[foto].caption)
                console.log(fotos[foto].title)
            }

the console log print undefined

why is that??? how can i get the information from db correctly in the client???
tnx all

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:44:33+00:00Added an answer on June 13, 2026 at 9:44 am

    If I understand correctly, you want to serialize the array of objects into the value of the input. Try this:

    - var jsonString = JSON.stringify(datos)
    input(type='hidden',id='imagenes',value=jsonString)
    

    The first line should turn the array of objects into a string which can then be placed into the value of the input.

    Then, when you read the value, you will have to parse the JSON.

    var fotos = $.parseJSON($('#imagenes1').val());
    

    I’m assuming that your use of $ implies that you are using jQuery.

    UPDATE: Explanation

    If you want an Object that is in memory in your server to be available to the Javascript running in the browser, you have to “write” that Object onto the page. That process is officially called serialization and the way to do that with Javascript is JSON.stringify. Once on the page in the value of the input, it is just a String. Javascript on the page has to turn that String into an Object (or in this case, an Array of Objects). That’s where JSON.parse comes in. Because older browsers don’t have JSON.parse, you should use a polyfill like jQuery.parseJSON to ensure that even older browsers will be able to turn the String into a Javascript Object.

    By the way, if you don’t need the data specifically in the hidden input but you think that that is the best way to do it, let me suggest another way. If your goal is to have var fotos contain the value of datos from the server, you can do that directly in a <script> tag on the page. Here’s how to do it in Jade:

    script
      var fotos = #{JSON.stringify(datos)};
    

    Check out this question about passing Objects to the page.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to pass an array of objects from my QtScript to C++ but
I want to pass a reference to an array from one object GameModel to
I want to pass a list array from the View to the controller on
I want to pass a custom made vector object containing data from background service
I have an array of objects and I want to pass them into a
Using the dust.js javascript templating engine, I want to pass an array directly: var
I want to pass an array of arbitrary struct pointers and a comparison function
In my Delphi development, I want to pass an array of const(that can contains
I want to pass around some values in an array that will always be
I have an array of Ids that I want to pass to the entity

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.