I couldn't solve how to save the previous shortened links. How can I do this?
Ejim Favour
@ejim11All comments
- @kaiohnrSubmitted over 2 years ago@ejim11Posted over 2 years ago
To make your data persist, you can use either localStorage or a backend like firebase. For local storage, after adding an data gotten from the api to the array that is used to display the shortened links, you can add the array to the localStorage.
//code localStorage.setItem("arrayName", array); this code above stores the array in the localStorage as a string. to get the array back, localStorage.getItem("arrayName");
the above code should be in a function that gets called every time the page loads. In the function, check whether there is anything stored and if there is, write a code that uses the data from localStorage to display the shortenedLinks. I know this is not concise but I hope it helps..
0 - @kaiohnrSubmitted over 2 years ago
I'd like to know what would be a better way to insert a zero in front of the number without have to repete those lines of code?
@ejim11Posted over 2 years agoconst timeLeftNow = { day: String(Math.trunc(totalSeconds / (60 * 60 * 24))).padStart(2, 0), hour: String(Math.trunc((totalSeconds / (60 * 60)) % 24)).padStart(2, 0), minute: String(Math.trunc((totalSeconds / 60) % 60)).padStart(2, 0), second: String(Math.trunc(totalSeconds % 60)).padStart(2, 0), };
0 - @kaiohnrSubmitted over 2 years ago
I'd like to know what would be a better way to insert a zero in front of the number without have to repete those lines of code?
@ejim11Posted over 2 years agoif you are using js, you can make use of paddingStart(0,2). meaning 0 is the number in front if the digit is from 0-9.
Marked as helpful1