This question already has answers here:
Is reading the `length` property of an array really that expensive an operation in JavaScript?
(6 answers)
Closed 4 years ago.
I'm an front end webdev intern at a small company where I'm making a panel which displays database statistics.
Now I noticed that on my panel which gives the count for how many entries are in a specific array the specific stat always takes a while to load (my other statistics appear nearly instantly).
Now my question is, does array.length actually loop though the whole array to get it's length?
The length is about 17000 and takes about 5 seconds to appear so I'm guessing that's the time it takes to loop through such a big array.
It is implementation dependent. The optimal implementation should know its length, where as the lazy one would iterate to figure this out.
Related
This question already has answers here:
How can I get query string values in JavaScript?
(73 answers)
Closed 4 months ago.
How can I make an html detects this? For example, I have a game in html, can I save the score to url like "example.com/game?score=15", detect this and set score to information in url? Or at least something like that? If you know what it's called, please tell...
I tried to search (cause I don't exactly know what it is) in google and youtube but no answer.
These are what are known as Request Parameters.
This question already has answers here:
Cartesian product of multiple arrays in JavaScript
(35 answers)
How to utilise TypeScript Variadic Tuple Types for a Cartesian Product function?
(2 answers)
Closed 10 months ago.
Hi can anyone please help me. I want to be able to generate all possible combinations of the array but only certain elements will be changing given two possible numbers to choose from. Their position is important too.
For example: let arr = [1,2,3, (4 or 5), (6 or 7), (8 or 9)]
I want to generate
1,2,3,4,6,8
1,2,3,4,6,9
1,2,3,4,7,8
.
.
.
.
This goes on until 1,2,3,5,7,9
I know it is very similar to binary numbers, I just don't know how to go about it and also the array may change in size so it can lead to a lot of options and possible outcomes.
Please. Someone help.
Edit: clarified the combinations I want to generate
This question already has answers here:
"Variable" variables in JavaScript
(9 answers)
Closed 2 years ago.
I wan to make a password storing program, and each password is stored into an independant variable, but I'd have to make an infinite number of variables and assign each input value to its corresponding variable.
So is there a way to make Javascript declare the variables by itself and assign it to its corresponding input value?
you can use array which can be collection of multiple values.
There will not be any specific limit of array in terms of length.
If you don't know about array, please have a look here Or you can try array online here.
Hope this helps, please let me know if you are still not clear.
This question already has answers here:
400x Sorting Speedup by Switching a.localeCompare(b) to (a<b?-1:(a>b?1:0))
(5 answers)
Closed 3 years ago.
Im sorting an array of objects alphabetically but not sure which way is more efficient. Im currently using the .sort() method and its working fine but would using the localeCompare() be a better alternative?
The localeCompare function is absurdly slow on many browser. Avoid it if possible. The other locale functions are really bad too, particularly the number to string ones.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need to generate unique random number to show into the textbox value and also perform insert,delete,update operation using java script. I need your solution which is better way using mysql or java script.? I'm trying java script and facing problem i could not show unique id.?
My java script code:
document.getElementbyId("random").value=Math.floor(Math.random()*10);
Due to the lack of code you're showing I can't give a specific answer, but I think the general idea is that you want a unique but random number assign into your text box?
unique number is easy, use things like timestamp. But if you need unique and random at the same time, the only "easy" method is generate a random number and check it against your database for duplicates.
just a heads up, if your random range is only from 0 to 10 it'll get fill up very quickly and duplicates will happens a lot, which slow down your program. I'd suggest at least a 10 times or more difference in the range of the random number and the expected total count of usage, like if you expect this program to run less than 10 times, use a range at least 100+
edit:
it is almost impossible to be sure a random number is unique unless you have all your previous generated number to check against. THAT SAID, there is a chessy way I can think of to kinda make a unique-random number, but it scales REALLY BAD the more you generates. The core idea is to change the FORMAT of the number everytime.
for example
1) generate a 2 digit number the first time, a 3 digit number the second time, a 4 digit number......
2) change the range of number, 0-10 for the first number, 11-20 the second number, 21-30 .......