A guide on extracting object details and incorporating them into an array using Parse.com and Express JS

I'm currently working on fetching an array of video (file) URLs from parse.com that match a specific playlist ID obtained from the URL.

var playlistVideos = Parse.Object.extend("playlistVideos");

    app.get('/:objectId', function(req, res) {

      var objectId = req.params.objectId;

      var queryVids = new Parse.Query(playlistVideos);
      queryVids.equalTo("playlistObjectID", objectId);
      queryVids.find({
        success: function(videoResults) {
          var videoArray = new Array();
          for (var i = 0; i < videoResults.length; i++) {
            videoArray[i] = videoResults[i].get("userVid");
            videoArray.push(i);
            //videoArray.push(videoResults[i].get("userVid"));
          }
          res.render('watch',
          {
            videos: videoArray,
            title: "test videos"
          });
        },
        error: function(error) {
          response.error("No videos found");
          console.log(error.message);
        }
        });

    });

When I print out the array to test it, the output is:

[object Object],[object Object],[object Object],[object Object],[object Object]

I'm unsure why it's showing these 5 empty objects when I have 8 corresponding to the playlist ID I'm trying to fetch.

I also tried using the .push method with the commented line and experimented with return(). However, I still haven't had any luck. Essentially, what I want returned is "http://example.com/file.mp4", "http://example.com/file2.mp4", etc.

I would greatly appreciate any assistance!

Answer №1

These are not just 5 blank objects, but rather objects that require conversion into a JSON string. You can achieve this by using the following code snippet:

console.log(JSON.stringify(videoArray));

To ensure you receive either 5 or 8 results, double-check that the objectId matches exactly with your playlistObjectID (including capitalization and spaces).

Answer №2

Discovering that JS has a .url() method truly saved the day for me.

All I needed to do was:

var holder = videoResults[i].get("userVid");    
videoURL[i] = holder.url();

This code snippet retrieves the URL string, and everything is functioning flawlessly now.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ensuring security against cross site scripting attacks on window.location.href

Currently, I'm utilizing window.location.href to redirect the page to an external URL: <Route exact path={rootUrl} component={() => { window.location.href =`https://${window.location.hostname}/www/testurl?google=true`; return null; }} /> How ...

Next.js triggers the onClick event before routing to the href link

Scenario In my current setup with Next.js 13, I am utilizing Apollo Client to manage some client side variables. Objective I aim to trigger the onClick function before navigating to the href location. The Code I'm Using <Link href={`/sess ...

Showcasing pictures on ReactJS

I am currently working on developing an application to showcase images on my React webpage. These images have already been uploaded to a local folder. In order to integrate my React application with a NodeJS server and MongoDB, I connected the two. My goa ...

Using the window.setInterval() method to add jQuery/AJAX scripts to elements at regular intervals of 60 seconds

I'm having trouble with automatically updating a div. I have a script that refreshes the page content (similar to Facebook) every minute. The issue is that this div is newly added to the page and contains some ajax/jQuery elements for effects. functi ...

How can I correctly format a conditional statement within flatMap while using Promise.all in Javascript?

Currently, I am developing a scenario where I use flatMap alongside Promise.all. Within the flatMap function, there are two specific conditions to consider: firstly, checking if the state of the originalObj is false or not before proceeding with the insert ...

Optimizing Static File Caching in Yii

Having a frustrating issue with Yii where my local development environment caches CSS and JS files. Despite making changes to the file, the edits do not reflect in the output and sometimes causes corruption leading to broken functionality. This problem see ...

Store the beginning and ending times in a MySQL database using Sequelize and Node.js

I am currently developing a project management application where I need to keep track of the start and stop time for user work. To achieve this, I have implemented two buttons in the UI - START and STOP. When a user clicks the START button, the following ...

Disable the use of componentWillUnmount in case of an incomplete form

I have implemented a form using redux-form and I am trying to set up a scenario where if any of the form's inputs have content and the user tries to navigate away from the page, a prompt should appear. My goal is to prevent the page from being unmoun ...

Error: Encountered an unexpected token F while trying to make a POST request using $http.post and Restangular

In our current project, we are utilizing Angular and making API calls with Restangular. Recently, I encountered an error while trying to do a POST request to a specific endpoint. The POST call looked like this: Restangular.one('aaa').post(&apos ...

What could be the reason for it allowing access with any password after correctly entering it once?

My issue involves two HTML files - one with a form for entering a password and another containing secrets. I've written some JavaScript code that seems to be causing problems. It refuses every incorrect password until the correct one is entered once, ...

Setting Data to a Variable from eBay JSON Object

I am currently exploring the capabilities of the eBay API in an attempt to extract the title value from an object. Here's a glimpse of what the data structure looks like: https://i.stack.imgur.com/sWhWo.jpg Despite numerous attempts with variations ...

The start and end dates must be distinct from one another within a one-year period

Hello, I have implemented Yup as a validator for one of my schemas Below is the code snippet to validate my schema: start: Yup.date() .max(new Date(), "Max date") .min( new Date(new ...

Refreshing Three.js Scene to its Initial State

I am in the process of developing a Visual Editor where I can manipulate objects by adding, deleting, and transforming them. Currently, my scene only consists of a 5000x5000 plane as the floor. I am looking for a way to reset the scene back to its origin ...

Explain how the 'next' function works within Express middleware and its role in directing the flow to a different function

I am fairly new to Node.js and currently learning Express.js. I am focusing on implementing "middleware functions" for specific routes. My question is regarding the usage of the "next" function. What exactly can we do after authentication using the "next ...

What is the best way to access a variable from a .js file?

Is there a way to access a variable defined in a JavaScript file from a Vue file and pass it to the Vue file? In the following code snippet, there is a template.js file and a contact.vue file. The template file converts MJML to HTML and saves the output to ...

Using the power of jQuery to create straightforward CSS animations

On my simple webpage, I have a main content area called content-wrapper and a sidebar on the right side named #sidebar-right I am attempting to create a margin on the right side of the content to prevent it from overlapping the sidebar, and have it expand ...

jQuery Animated List - Nested items are unresponsive to clicks

Looking to create a dynamic nested list using jQuery for animations, but unsure of the best approach. Currently, I'm adjusting the length of the parent list item and revealing the nested items. The issue is that the parent item's length covers ...

Troubleshooting a misformatted JSON string that lacks proper double quotes in Java Script

{ DataError: { user_id: [ [Object] ] } } I want to transform this string into JSON structure like below: { "DataError": { "user_id": [ [Object] ] } } Is there a potential method to achieve this outcome from incorrectly formatted JSON string? ...

Add a hyperlink within a button element

I am looking to add a route to my reusable 'button' component in order to navigate to another page. I attempted using the <Link> </Link> tags, but it affected my CSS and caused the 'button' to appear small. The link works if ...

Transfer only certain directories located within the primary directory

Imagine having a main-folder, which contains folders of type my-folder-x. Within these my-folder-x folders, there are subfolders and files. -main-folder -my-folder-a -build-folder -demo-folder dummy.js dummy.css my.json -dummy-folder - ...