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.

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
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
2 votes

Sorting dates in this format (DD-MM-YYYY)

As the code is reviewed in other answers, I'll suggest you to different approach. let getTimestamp = str => +new Date(...str.split('-').reverse()); dates.sort((a, b) => getTimestamp(a) - getTimestamp …
Tushar's user avatar
  • 3,002
3 votes

Selecting checkboxes based on URL parameters

As pointed out by Heslacher, you're repeating the code. The value of url can be cached and used in following if statements. To get the value of chk param value, use RegEx. You're using split which wi …
Tushar's user avatar
  • 3,002
0 votes

Optimization of Javascript Function swapping out images for gifs

Number of functions 2n You're creating two functions per image one to handle mouseenter event and other to handle mouseout event. If you look at the mouseenter handler of all the images, you'll notic …
Tushar's user avatar
  • 3,002
1 vote

jQuery replace HTML

As Barmar explained in his comment, you can use the function as argument to text() and html(). These methods iterate over all the elements matched by selector so, there is no need of each. Also, m-mu …
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
2 votes
Accepted

Terminated due to timeout Mapping phone numbers

Naming Single character name is a bad practice. Use the descriptive names for variables. r => rows o => noOfRecords c => noOfRows x => ... They are not searchable and can be easily confused with n …
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
3 votes

Create list of objects from an object where the key is properCase using Lodash

The code looks like you're passing the processed data to autocomplete. Naming formatToInput: This gives no idea of what the function is doing. empty: Is it really empty at the end of formatToInput? …
Tushar's user avatar
  • 3,002
1 vote

Change text and styling of a form control when a slider value changes

('background', color); } } // Get message at that index $('#desc').text(description[value]); }); I'll suggest to move the styles in CSS classes and add/remove the classes using JavaScript
Tushar's user avatar
  • 3,002
1 vote
Accepted

Toggle the visibility of sections of a form

To access this from JavaScript when clicked data() can be used $(this).data('selector') Note that $(this) inside event handler refer to the element on which the event has occurred. We're ready!!! …
Tushar's user avatar
  • 3,002
2 votes
Accepted

Simple Javascript Accordion

I don't see any issue with code other than below two things. First, I'll suggest is to use classList.toggle instead of contains and then add/remove class. See browser compability and if target browse …
Tushar's user avatar
  • 3,002
3 votes

Merge two sorted arrays, make more efficent (O(a+b))

Naming a, b, what are not meaningful, descriptive and searchable names. arr1, arr2 and needle are descriptive names. Code Duplication There are two for loops in countInArray and both are same. A fu …
Community's user avatar
  • 1
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

15 30 50 per page