I want to check for the empty array in react JavaScript. But when I am using the question mark for checking that is it undefined or not then the react and is crashing. I am using something like this: In the useEffect hook I’m using setverlist(response.versions.version). Here versions is object. And in i…
Tag: javascript
How to write this function with forEach?
I am trying to group the people by their age and as you can see, my code works with the reduce method. I managed to get this working but now I want to do the same with forEach method. Here’s my code: Answer Reduce accepts initial value that you update each iteration and return. So if you wish to use
React Native – Assign value from promise to variable
I have a couple repositories containing database calls such as getUser and getUsers. Now I export those repositories as followed: This leads to me having to do things like this: The intellisense says userRepository is: Is there a way how to assign the functions to userRepository without me having to do any th…
I need help to overwrite images on html page upon clicking a button [closed]
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers. Closed 6 m…
How to add files from file input into array in Firefox browser?
(I’m using vue 3) I’m adding files from input file to array, then I conditionally render these file names. All working good on Chrome. Problem is when using Mozilla Firefox. In this browser array of files is overrided by last added file, for example: add file-1 || output: file-1 add file-1 and nex…
Swapping array with alternative numbers
In an array take alternate numbers and swap them. Put it again in the place of array again e.g., arr = [8,7,4,6,9,3,2,1] newarr= [8,1,4,3,9,6,2,7] The Code which I tried is below one This is not the correct way to proceed. Answer When you consider every odd indexed element to be alternate –
Using Javascript libraries in Curity scripts
I’m getting to grips with Curity, and it looks very promising, but I need to replicate a weird hashing function from a legacy system. The built-in context class passed in to a credential transformation procedure does not include the algorithms I need, so I want to use the crypto-js library. Unfortunatel…
Filter html elements based on data attribute
I have the following html structure And what I want to do is to get the count of child divs that contains different data attribute. For example, I’m trying this: But that code is returning 6 and what I want to retrieve is 4, based on the different data-customId. So my question is, how can I add a filter…
How can I allow only alphanumeric including Chinese, Japanese and all that cryptographic languages?
I’m currently trying to filter out any bad char from a string to only allow alphanumeric ones but I need to include Chinese, Japanese and all that non-Latin languages as well. After some hours of reading RegEx, I’m more confused than informed. Currently I have: Without the {Han} everything works w…
How to get a boolean value if a location coordinate is within the given $geoWithin or $geoNear radius in mongoose?
I want to get a boolean value eg. true or false if a location coordinate is within the given radius is the $geoWithin query or $geoNear pipeline in mongoose aggregate function. If I user $geoNear in the mongoose aggregate pipeline then it only returns the filtered result. So far I have done the following, The…