i have the following code that generates a new element on an array in my localstorage each time i click on a button My problem is that I’ve tried to create a validation to check if the element has already been added to the local storage, so in that case there should appear the alert, but it’s not …
regex replace for multiple string array javascript
I have a array of string and the patterns like #number-number anywhere inside a string. Requirements: If the # and single digit number before by hyphen then replace # and add 0. For example, #162-7878 => 162-7878, #12-4598866 => 12-4598866 If the # and two or more digit number before by hyphen then repl…
How to integrate compound React(Typescript) component into html page
I have the old website which was built by Vanilia Javascript. And now I am converting it to React. So I am going to render compound React(Typescript) component in HTML page. But it does not work. Here is my code. app.html My component – Test.tsx I found many examples for this, but it was a simple compon…
Hamburger icon css animation into an x
Im trying to make a hamburger icon turn into an x on click and then revert when clicking again. Ive got the animation set up i think but i need it to trigger on click rather than be constantley set. The ToggleNavLinks function is only used set an elements display to none unrelated to the hamburger icon. Menu …
How to validate whether a string-value is a parsable date-format?
I am running the code below, checking if the string is a date. One of my input values is ‘text’ which returns the NaN value but my if clause does not work as expected. Answer You’re almost there: Instead of comparing whatDate to ‘NaN’ use the function isNaN(): Alternatively, if y…
Nextjs UseEffect is not rendering on route change
I am having problem with a useEffect inside a component which is in every component. I have made some authentication and redirects in that component but I figured that when I use Nextjs link or the go back button from the browser, the Layout useEffect is not re rendering which means it is not checking if the …
How do I update my NavBar once a user is logged-in (from ‘log in’ to ‘profile’) using React & Firebase?
I’m new to Reactjs & Firebase, but I’ve managed to set up a signup/login system- now once the user logs in, I have them redirected back to the home page, but I want the nav bar to display ‘profile’ instead of the original ‘log in’. I know this is something to do with Co…
Why won’t my variable increment everytime I run the program?
This is a game where the player plays against the computer in a rock paper scissors game. I am trying to make the computer score or player score go up depending on which one wins. But it does not increment when I try to run it. I am new to functions and returning values so I do not really understand
How can I make my input to be only limited to a maximum of 10 numbers and don’t allow any characters?
I want to be able to put a maximum length for the phone number entered and don’t allow any characters too. However, with the format below it does limit the person to enter 10 characters but it also allows any other character to be added too. Now if I change type to type=”number” maxLength wi…
Recursively filter an array of infinitely nested objects by mutliple matching conditions but only return parent that has an instance of both matches
I have the following array of objects; however this could be any unknown key/value and be infinitely nested, for now this is a testing sample: My current implementation is as follows: Basically I am adding to the “selected” array then using that to filter the data array by. I do want to ensure the…