Skip to content
Advertisement

Tag: loops

A function which takes an array as argument, with a forEach loop which console.log each element and each index for every iteration inside the function

I have to create a function which takes an array as argument, with a forEach loop which console.log each element and each index for every iteration inside the function. Also inside the function declare a variable called count, and increment it by one for each iteration then return count. I wrote this function: But I get the following error: How

React map through json object

I am having trouble finding a way to iterate through this nested JSON data. I would like to display elements into select option list. I store my data in a state after a request. I already tried: Last one gives my TypeError: Cannot read property ‘map’ of undefined. If i try to set my state to setFilterData(res.data.regions) then i can

Create a loop to compile multiple records into a new variable

At the moment I am fetching metadata attached to individual record numbers. The process I am using works, but its somewhat cumbersome, especially for larger batches of records: I am trying to improve this process by creating a loop or sorts to insert each record number to get the same result as above in allData. However, I am not getting

Increment array up to max items

I’ve written this code. It rotates two divs like a card flip using css transform every 1000ms and displays new text in the div, which is drawn from an array. It runs infinitely. But once the array reaches its end I get an ‘undefined’ value because the i++ is incrementing on the final array item. I have been going crazy

Reading values from dictionary in Javascript

I am trying to read tags from a selected collection of bibliographic data in ZOTERO with Javascript. For those who aren’t familiar with ZOTERO: it has an in-built “run JS” panel to work directly with items selected / marked in the standalone version. This is the script I am using to read data from a selected folder and access the

How can I log the index of each array item?

I’m a beginner and struggling with this exercise. Can anyone tell me why the console is logging the index of both characters as 1. I want it to log the character ‘a’ every time it appears in the word. So for example, if we ran the function with the word ‘Saturday’ and ‘a’ as below, it should log an array

Advertisement