Use Q.js's Q.all() method when dealing with an array of promises of unknown length

I am looking to retrieve an array of promises using Q.all(); such as the code snippet below:

return Q.all([
              list[0].getCssValue('height'),
              list[1].getCssValue('height'),
              ...,
              list[list.length-1]
              .getCssValue('height')
             ]);

I want to return all items in the list which can be obtained by array.length.

The issue I am facing is that I am unable to

   for(var i = 0; i < list.length; i++)

in order to get the return items like

list[i].getCssValue('height'); 

So, how can I achieve this?

Answer №1

Yes, it is possible to achieve this by simply creating a new array:

let newArray = [];
for(let i = 0; i < originalArray.length; i++){
    newArray.push(originalArray[i].getAttribute('value'));
}
return Promise.all(newArray); // waiting for all attribute retrieval actions

Alternatively, you can use a more concise approach using the .map method to transform each element in an array:

return Promise.all(originalArray.map(function(item){ return item.getAttribute('value'); });

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

Adjust the height of a div vertically in Angular 2+

Recently, I started using angular2 and I've been attempting to create a vertically resizable div without success. I have experimented with a directive for this purpose. Below is the code for my directive: import { Directive, HostListener, ElementRef ...

Lost Vuex struggles when it is manually navigating a route in Vue-router

Exclusively on Safari browser, I encounter an issue when manually entering the URL in the navigation bar after logging in. For example, if I type "http://x.x.x.x:8080/gestione", the browser loses the vuex store state (specifically the gest_user module with ...

Manipulating the content of h1 tag using Jquery when selecting from a dropdown menu

As I was exploring this Fiddle I stumbled upon, http://jsfiddle.net/JBjXN/ I've been working on a functionality where selecting an option from HTML <h1>Select a Show</h1> <select class="radio-line" id="radio-manager&quo ...

Attempting to save the result of a fetch call into a variable for the purpose of rendering it as a list in a

I'm attempting to fetch the top 5 NFT collections based on volume and display them in a table format. However, I'm facing an issue where the data is not being mapped correctly and when I click the "get" button, all content on the webpage disappea ...

The output of new Date() varies between app.js and ejs

app.get("/test",function(req,res){ var d = new Date(); res.send(d); }); When I access mydomain/test, it displays the output "2019-03-19T04:50:47.710Z" which is in UTC. app.get("/testejs",function(req,res){ res.render("testejs");}); Below is the content ...

Glitched Water Reflection in THREE.js

Creating a water scene using JavaScript. I followed the official examples to set up the scene, but the reflection seems off after loading an external GLTF model. Initially everything looks fine, but once I start moving the camera, things go awry. I suspe ...

Calculate the total cost for each row in a table by multiplying the quantity and price using jQuery, then display the result

I'm encountering an issue with my table row calculations involving price and quantity. The calculation results show up correctly in the console, but when I try to display them back on the table, the total sum of the first row gets duplicated into all ...

Is there a way to detect a class change using jQuery?

Below is an example of a div: <div id="components-reconnect-modal" class="components-connecting-show"> <div id="1"> <div id="2"> <div id="3"> <div id="4"> </div> The ID will remain constant, but the class will ...

React Native: useEffect not triggering upon navigation to a screen that is already active

When I click on a notification in my React Native app, it navigates me to a chat screen. In that chat screen, there is a useEffect function that fetches the chat messages. The issue arises when the chat screen was the last screen opened before closing the ...

What are the best practices for utilizing databases with both Javascript and JSF frameworks?

I am currently following the recommendations provided by @BalusC, with additional guidance available here. (The reason I'm posting this here is because it's not related to my previous question). My goal is to retrieve data from my database and d ...

Is the AJAX $.ajax() function and setInterval() method activated only when a user is actively viewing the page?

The following code was created by me in order to refresh or reload the content within the div id='bitcoin_blocks_table', which only occurs when a user is actively on the website. I noticed that if no one is on the site and I return after 2 hours ...

Position object in the middle using jQuery and CSS

Trying to center an absolutely positioned object horizontally using CSS and jQuery is proving to be a challenge. The use of jQuery is necessary due to the varying widths of the objects. Hover over the icons in my jsFiddle to see the issue. Check out the j ...

code in html/javascript that is securely implemented for adobe air applications

Creating a desktop application using Adobe Air is my goal, but I have concerns about the security of the HTML/JavaScript source code. My application will feature paid media content, and I am hesitant to expose any URLs associated with it. What methods ca ...

Can we utilize object properties in this manner?

Hey there! I've been experimenting with the react-bootstrap library recently, trying to get better at using it. While going through the tutorial, I came across some ES6 code that caught my attention. function FieldGroup({ id, label, help, ...props } ...

Issue: Spaces are not being displayed between items in the @Html.DisplayFor statement within the Foreach

I have encountered a few similar queries on this platform and attempted the suggested solutions, but unfortunately, they did not resolve my specific issue. Within my view, I am using @Html.DisplayFor in a Foreach loop to display all GroupIDs in a particul ...

Steps for setting up node-openalpr on a Windows 10 system

While attempting to install npm i node-openalpr, an error is occurring: When using request for node-pre-gyp https download, I encounter a node-pre-gyp warning and error message. The package.json for node-openalpr is not node-pre-gyp ready, as certain pr ...

Struggling to properly send props to the child component in Vue 3

Is there a way to pass data from the request through axios in the root component to the child using Vue? Currently, only the "title" field is displayed correctly, but I also need to output the "body". Note: This is my first time working with Vue and I&apo ...

What are some creative ways to provide video responses to a list of questions?

My task is to create a popup that includes questions and video responses. The challenging aspect for me is how to ensure each question displays a different video in the same location. Additionally, when the user first opens the popup, the initial question ...

What is the best method for breaking down this JSON data into distinct 'objects'?

I am struggling with deserializing JSON data into multiple instances of an object I have defined. Here is how the object is structured: function Question_Value__c () { this.Id=null; this.Name=null; this.Question__c=null; this.Order__c=null ...

Guide to smoothly scroll to the top of an element containing collapsible panels using Jquery

I've encountered an issue with a series of divs that are set to toggle the state of a collapsible div upon clicking (similar to an accordion widget). The functionality works as intended, but I'm facing a challenge - I want the page to scroll to t ...