Search Results
| Search type | Search syntax |
|---|---|
| Tags | [tag] |
| Exact | "words here" |
| Author | user:1234 user:me (yours) |
| Score | score:3 (3+) score:0 (none) |
| Answers | answers:3 (3+) answers:0 (none) isaccepted:yes hasaccepted:no inquestion:1234 |
| Views | views:250 |
| Code | code:"if (foo != bar)" |
| Sections | title:apples body:"apples oranges" |
| URL | url:"*.example.com" |
| Saves | in:saves |
| Status | closed:yes duplicate:no migrated:no wiki:no |
| Types | is:question is:answer |
| Exclude | -[tag] -apples |
| For more details on advanced search visit our help page | |
Results tagged with javascript
Search options not deleted user 6502
JavaScript is a versatile, high-level programming language. It is the programming language in all browsers, and can be used for back-end programming with Node.js. Use this tag for questions regarding vanilla JavaScript; optionally tagged with an ECMAScript version. If you are using a preprocessor such as TypeScript please tag with that too.
3 votes
Accepted
Maximum number of values in an array
There is no native way to do this so your general logic seems sound. Here's some improvements, you might consider: Make sure the pushMax function is not enumerable so people who iterate arrays with …
1 vote
Accepted
Should I write my fadeTo function differently?
Well written animation functions typically use a tweening algorithm that checks the system clock to see how much time is actually remaining in the originally specified time allotment and then adjusts …
7 votes
Accepted
Declaring JavaScript variable and then overwriting it multiple times
You can using chaining, move the toLowerCase() to simplify a little and return the last statement directly: function() { var el = {{element}}; el = (el.innerText || el.textContent); …
6 votes
Accepted
Reducing code with two identical objects
You can combine the two identical assignments at the end into the same line rather than recalculating the same value again: for (var i = 0; i < ticks.length && i < ticks2.length; i++) { var tick …
1 vote
Accepted
Should I change the following to switch or else if statements?
else if would be more efficient because it wouldn't continue to evaluate comparisons that you already know won't match. It would also be more efficient to cache some values here so you aren't reval …
2 votes
Javascript assert function
You could write it as: function safeLog(s) { if (window.console && window.console.log) { console.log(s); } } function assert(a, b, message) { if (a != b) { safeLog("Faile …
3 votes
Accepted
Showing and hiding element, making my code more useful
Item 1: I'd suggest getting rid of all global variables except tog. They don't look like they are needed and just open you up for a potential conflict with other global variables. Item 2: This line …
1 vote
Accepted
JavaScript function for printing a countdown
Try this: var time_format = (function() { var names = "yr mo w d h m s".split(" "); return function(time) { var elms, ret, i, n; elms = [ time / 29030400, …
1 vote
New to immediately-invoked function expression with JavaScript, curious about placement
In this case, it makes no difference at all. This IIFE really has no reason for even being there because all it contains is a single function. Your code does use any of the usual benefits of an IIFE …
3 votes
Accepted
Varying a second drop-down's options based on a first selection
For starters, you can remove a lot of duplicate code from the populateBilling() function like this: function populateBilling(planName) { var options = { basic: { "Option" : [ …
0 votes
Generating an array of unique values of a specific property in an object array
I'm not sure exactly what you're looking for, but here's an implementation in plain Javascript: var table = [ { a:1, b:2 }, { a:2, b:3 }, { a:1, b:4 } ]; function …
2 votes
Finding patterns in a string
Here are two different ways of doing this, one using repeated calls to .indexOf() and one using repeated calls with a regex to .exec(). The regex solution requires the pattern argument to be a regex …
3 votes
Accepted
Promise.spread "Polyfill"
Your implementation is taking .then(a, b) and mapping it to .then(a).catch(b) which is not exactly the same thing. An exception or return of a rejected promise in a in your implementation will hit th …
2 votes
Accepted
DNS lookup function
You could launch all the operations in parallel and then call the callback when the first one succeeds or when all have failed. Here's a way to do that: function checkInternet(callback) { var se …
2 votes
Copying and pasting one inputs value into other input with the same name
Why not at least save the intermediate to avoid rerunning that: $(document).on('click', '.--copy', function () { var obj = $(this).closest('div').find('input'); var input_name = obj.attr('nam …