I’ll fetch data from an API, When I pass my getServerSideProps data to index.js, the prop array is in order by rank. [1,2,3..etc]. ex: data When I alter that data into a different variable, for example: console log shows data is now sorted by price too, when I only wanted topPrice to be sorted, why? Answer sort function alters your
Tag: javascript
React useState, setState and {state} in return
I come across the rendering issue with React State. The problem is that {state} in return get value one beat late. But the console log in handleChange shows right value. If the previous value of state is 9, current value of state value is 10 then the console.log({state}) in handleChange shows 10 and the <span>{state}<span> in return shows 9. It
HTML + JavaScript custom player for multiple videos on a website page
EDIT: I have found the solution, posted and marked as the best answer below. I’m coding a portfolio website for myself using HTML, CSS and JS and I need to add multiple videos on a lot of pages. I followed some tutorials to learn how to customize the video player, but it only works for one specific video on the
Why is URL.creatObjectURL(blob) giving a cross-origin frame error in NodeJS/React application
I have never had this happen before and am not sure why it’s happening. I have a component written to display PDF files in an iframe as part of a larger application. I am retrieving a BLOB stream from the server and attempting to create a URL for it to display in the iframe but it keeps giving me a
Adding new array in object
I’m working on an application that involves a somewhat complex user registration. Something similar to this. When a user adds a new address to a person he is registering, he should add a new address to the person and keep the previous data. But it creates a new data array with just the address data, outside of the specified person.
Transition the height of an onclick drop down text with css and js
I tried to make a section where I talk about my hobbies etc., but the text was a bit too much, so I decided, that you only read the first sentence and can click it to read the whole text. I used some CSS and JS, but I didn’t use Jquery. Now I want to add a transition to it,
Json Array Pushes Data Twice to File Tree with React
When pushing data into a file tree, it pushes 2 sets of the same data and I am not exactly sure why. I have a simple json array that looks like this: I am trying to push 4 files I have into it like this by calling this function: This is how addFileToTree is being called: The result has been
JavaScript converting the string “constructor” to [Function: Object]
I’m building a parser for a simple interpreter in JavaScript. I have a preprocessor method that removes specific tokens from an input list of tokens produced by the tokenizer: Each token is an object like this, with both type and value being strings: Somewhere in this function, when tokens[i].value == ‘constructor’, said value is being converted to the actual JS
Why is my decryption function not working?
I created a function to encrypt and decrypt messages. the encrypting works fine. but when I try to log encrypted Hello World! it just logs H. Fixed it, i edited the encoding system to place a – between chars and the decoding system to just split the message at – and check if the element starts with c n or
JavaScript String indexOf() selects also 1&3 instead of only 13
I have this indexOf(), the issue I have is that when norms[] has an dataset like 2,13 that options that are set as selected in norm_id[‘+nr+’][] are not only the values 2 and 13 but also the values 1 and 3 Any suggestions how to solve this? Answer I have solved the issue with the code below. @Andreas thx for