Skip to main content
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
Search options answers only not deleted user 79668

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.

20 votes
Accepted

Regex to enforce password requirements

Here's the code for JavaScript. …
Tushar's user avatar
  • 3,002
15 votes
Accepted

Functions to hide and reclaim first visible publication on a page using Selenium

As the code is similar, they can be merged together. I'll suggest you to break down the functions into smaller reusable chunks which will follow the Single Responsibility Principle (SRP). These funct …
Tushar's user avatar
  • 3,002
14 votes
Accepted

Basic JavaScript template engine using replace, match and RegExp

JavaScript match => map => n * replace In the three functions, you're first using match to get the matches then iterating over it and using replace inside it. This is not at all necessary. … Which equals operator (== vs ===) should be used in JavaScript comparisons? For default values, || can be used instead of ternary. The default value for _array should be [] instead of {}. …
Tushar's user avatar
  • 3,002
13 votes

Extract numbers from a string-Javascript

The code will fail in below cases: Negative numbers Decimal numbers Units other than px(e.g. pt, %, vw, vh, ...) Moreover, the numbers array contains space before numbers and an empty string at th …
Tushar's user avatar
  • 3,002
12 votes
Accepted

Get character occurence count along with character in a string

I don't see any problem in your code except using of equality and inequality operators. Use strict equality(===) & inequality(!==) operators. I'll suggest to use RegEx. .replace(/(.)\1*/g, functio …
Tushar's user avatar
  • 3,002
12 votes
Accepted

Palindrome checker in JavaScript

return str === reversedStr; See Which equals operator (== vs ===) should be used in JavaScript comparisons? …
Tushar's user avatar
  • 3,002
11 votes
Accepted

Using regex to replace strange characters

Note that in these demos, PHP is selected as the steps taken to match is not shown for JavaScript. … The effect should be similar in JavaScript. Note that the __(two underscores) are redundant as _ is already added in character class and with g flag it'll remove all occurrences. …
Tushar's user avatar
  • 3,002
8 votes

Determining if two words are anagrams

Your solution is not removing punctuations and spaces before checking if two strings are Anagrams. Also, the code can be optimized. First, remove all the spaces and punctuation marks from both the …
Tushar's user avatar
  • 3,002
6 votes

Convert Persian and Arabic digits to English

You can use capture groups return string.replace(/([٠١٢٣٤٥٦٧٨٩])|([۰۱۲۳۴۵۶۷۸۹])/g, function(m, $1, $2) { return m.charCodeAt(0) - ($1 ? 1632 : 1776); }); $1 is the character matched by [٠١٢٣٤٥٦ …
Tushar's user avatar
  • 3,002
6 votes
Accepted

Add/Remove class on scroll depending on scroll length

The code can made very short. $(window).scroll(function () { var scrollTop = $(document.body).hasClass('home') ? 510 : 293; $('#navigation-wrapper').toggleClass('navbar-fixed-top', $(this).sc …
Tushar's user avatar
  • 3,002
6 votes

JavaScript Rain

See What is the (function() { } )() construct in JavaScript? Implicit Global Variable i used in for is implicit global. It is not declared(no var, let, const) but used. … JavaScript provides a better way to get the width and height of browser. So, 1600 will become window.innerWidth and 1400 will become window.innerHeight. …
Tushar's user avatar
  • 3,002
5 votes
Accepted

Loop through string array with exit if test passed

Join the string to create a jQuery selector var elementTypes = ['btn', 'textbox', 'ui-jqgrid', 'flexboxdiv', 'headerlabel']; var selector = '.' + elementTypes.join(', .'); return $('.TestModule').fi …
Tushar's user avatar
  • 3,002
5 votes
Accepted

Dynamic attribute key selector

Naming Conventions The variable all doesn't tell what it contains. allElements does reflect what it contains. clean, i, foo, capture - huh? filter, the name of the function has nothing to do with …
Tushar's user avatar
  • 3,002
5 votes

A function to split an string of alphabets and numbers into arrays and sort them respectively

You can use RegEx to extract the sequence of alphabets or numbers. To match alphabets/number, use character class in Regular expression as below /[A-Z]+|[0-9]+/ to match all occurrences, use g(glob …
Tushar's user avatar
  • 3,002
4 votes
Accepted

Tooltip-overlay following the mouse pointer

Should I try to concentrate more on JavaScript only? I mean: Should I try to reduce the mandatory HTML-, CSS-code to a minimun? I think, the code i.e. HTML and CSS are minimal. … Storing the tooltip on the HTML elements is correct way rather than storing it in JavaScript. So, NO. You should not only concentrate on JavaScript. Or is Okay the way I have done it? …
Tushar's user avatar
  • 3,002

15 30 50 per page