2,533,862 questions
12103
votes
50
answers
13.1m
views
How can I remove a specific item from an array in JavaScript?
How do I remove a specific value from an array? Something like:
array.remove(value);
Constraints: I have to use core JavaScript. Frameworks are not allowed.
8716
votes
67
answers
3.2m
views
How do I check if an element is hidden in jQuery?
How do I toggle the visibility of an element using .hide(), .show(), or .toggle()?
How do I test if an element is visible or hidden?
8514
votes
32
answers
1.2m
views
What does "use strict" do in JavaScript, and what is the reasoning behind it?
Recently, I ran some of my JavaScript code through Crockford's JSLint, and it gave the following error:
Problem at line 1 character 1: Missing "use strict" statement.
Doing some searching, ...
7698
votes
58
answers
8.0m
views
How do I redirect to another webpage?
How can I redirect the user from one page to another using jQuery or pure JavaScript?
7650
votes
42
answers
1.2m
views
var functionName = function() {} vs function functionName() {}
I've recently started maintaining someone else's JavaScript code. I'm fixing bugs, adding features and also trying to tidy up the code and make it more consistent.
The previous developer used two ways ...
7614
votes
86
answers
1.6m
views
How do JavaScript closures work?
How would you explain JavaScript closures to someone with a knowledge of the concepts they consist of (for example functions, variables and the like), but does not understand closures themselves?
I ...
7549
votes
40
answers
3.3m
views
How do I remove a property from a JavaScript object?
Given an object:
let myObject = {
"ircEvent": "PRIVMSG",
"method": "newURI",
"regex": "^http://.*"
};
How do I remove the property ...
7406
votes
3
answers
8.2m
views
How to check whether a string contains a substring in JavaScript?
Usually I would expect a String.contains() method, but there doesn't seem to be one.
What is a reasonable way to check for this?
6720
votes
43
answers
2.1m
views
How do I return the response from an asynchronous call?
How do I return the response/result from a function foo that makes an asynchronous request?
I am trying to return the value from the callback, as well as assigning the result to a local variable ...
6353
votes
72
answers
4.5m
views
How do I include a JavaScript file in another JavaScript file?
How do I include a JavaScript file inside another JavaScript file, similar to @import in CSS?
6340
votes
38
answers
2.4m
views
What is the difference between "let" and "var"?
ECMAScript 6 introduced the let declaration keyword.
I've heard that it's described as a local variable, but I'm still not quite sure how it behaves differently than the var keyword.
What are the ...
5763
votes
41
answers
5.4m
views
Loop (for each) over an array in JavaScript
How can I loop through all the entries in an array using JavaScript?
5645
votes
47
answers
2.2m
views
Which equals operator (== vs ===) should be used in JavaScript comparisons?
I'm using JSLint to go through JavaScript, and it's returning many suggestions to replace == (two equals signs) with === (three equals signs) when doing things like comparing idSele_UNVEHtype.value....
5498
votes
50
answers
4.6m
views
How do I replace all occurrences of a string in JavaScript?
Given a string:
string = "Test abc test test abc test test test abc test test abc";
This seems to only remove the first occurrence of abc in the string above:
string = string.replace('abc', ...
5471
votes
79
answers
4.8m
views
How can I validate an email address in JavaScript?
I'd like to check if the user input is an email address in JavaScript, before sending it to a server or attempting to send an email to it, to prevent the most basic mistyping. How could I achieve this?...