I have two arrays, array1 has all objects and array2 has filtered objects based on a search string. Currently I am rendering array2 (which will contain all objects from array1 when the search string is empty, but will return only filtered objects if search string isn’t empty) to the user but I would lik…
Tag: arrays
get the number of inputs given to a function js
Assume i have created a function function findInputGiven(){} and i called it somewhere below twice findInputGiven([1, 2], [3, 4]), findInputGiven([1, 2], [3, 4], [5, 6]). This function can be called with multiple inputs, i dont know how many inputs will be available in my findInputGiven function. How can i ge…
Inserting text content using same class multiple times
I’m currently trying to insert text content that change depending of image validation using a single class for multiple divs. Any help is appreciate! HTML Right now using the next Javascript it’s inserting the text content but it only does it once per “.spanner” class, not in the rest.…
Iterating through a an array executing a switch statement returns TypeError: Cannot assign to read only property ‘location’ of object ‘#’
I have a read only array that i copied to become a mutable array let mutableForecast = […forecast] I am taking that new array and iterating through it with forEach so i can mutate the array. im trying to use some flow control with a switch statement, but I am getting TypeError: Cannot assign to read onl…
Initializing my variable doesn’t works by first click, but by second click it works
if I enter an article number, for example 100100 and then click on the button, my array parent is empty, although it actually has to be overwritten by the method called. however, when I click the button a second time, the array is no longer empty. Why is that? I want my array to be overwritten after the first…
Javascript Array of Functions get auto executed
I need to make a sequence of Promises that are executed in a queue. They are dynamic so I need to put them in an array (I have found an article that explains how to). The problem is that my array of functions autoexecuted it self (version with a normal funciton): I don’t know why, an array of functions …
JS for loop loops once
My problem is that I am trying to iterate over an array several times, however, my for loop will only iterate over the array once (Or so it seems to me) which causes the outcome to be wrong. What I am trying to do is loop on this array: let arr = [“e5”, “b2”, “a1”, “c…
Can’t add an event listener to an element from an API
I am building a trivia webapp using an API and i want to add an event listener to the button with the correct answer so that when the user clicks it it will display a message saying they’re right and it’ll get a new question. Here’s how the code looks: It tells me that the AddEventListener i…
How to filter unique values of array object when in comma separated string
I have this array, where ‘data_type’ holds values in a comma separated string: Original array: How to catch, filter and build new array with all unique values? Target array: Here is a Fiddle: https://jsfiddle.net/grnewkzs/1/ Answer you need to know why and how, or your lean nothing…that̵…
What is the correct way for getting data from this object in ReactJS?
I’ve got ReactJs who is getting response from backend server. console.log(content) is looking like this: Now in my react app I can easily access to data with {content.price} eg. and I will get 75.284. Now trouble I’ve got is when accessing content.data. I can access to data and console.log it, whe…