Java Script

JavaScript (not to be confused with Java) is a high-level, dynamic, multi-paradigm, weakly-typed language used for both client-side and server-side scripting. Its primary use is in rendering and allowing manipulation of web pages. Use this tag for questions regarding ECMAScript and its various dialects/implementations (excluding ActionScript and Google-Apps-Script).

59 votes
25 answers
3K views
Checking if a key exists in a JavaScript object?

How do I check if a particular key exists in a JavaScript object or array? If a key doesn't exist, and I

avatar
Yolando
0 1 0 9
asked 07 September, 2021
56 votes
20 answers
1.7K views
How to insert an item into an array at a specific index (JavaScript)

I am looking for a JavaScript array insert method, in the style of: arr.insert(index, item) Preferably in jQu

avatar
Arline
0 1 0 9
asked 07 September, 2021
58 votes
30 answers
405 views
Loop through an array in JavaScript

In Java you can use a for loop to traverse objects in an array as follows: String[] myStringArray = {"Hello",

avatar
Charis
0 1 0 9
asked 07 September, 2021
61 votes
30 answers
1.9K views
What is the !! (not not) operator in JavaScript?

I saw some code that seems to use an operator I don't recognize, in the form of two exclamation points, l

avatar
Adolfo
0 1 0 9
asked 07 September, 2021
59 votes
30 answers
2.4K views
How do I copy to the clipboard in JavaScript?

What is the best way to copy text to the clipboard (multi-browser)? I have tried: function copyToClipboard(tex

avatar
Yolando
0 1 0 9
asked 07 September, 2021
65 votes
30 answers
1.1K views
How do I test for an empty JavaScript object?

After an AJAX request, sometimes my application may return an empty object, like: var a = {}; How can I che

avatar
Nereida
0 1 0 9
asked 07 September, 2021
61 votes
30 answers
1.2K views
Which "href" value should I use for JavaScript links, "#" or "javascript:void(0)"?

The following are two methods of building a link that has the sole purpose of running JavaScript code. Which i

avatar
Lynette
0 1 0 9
asked 07 September, 2021
59 votes
8 answers
1.8K views
Why does Google prepend while(1); to their JSON responses?

Why does Google prepend while(1); to their (private) JSON responses? For example, here's a response whil

avatar
Shantay
0 1 0 9
asked 07 September, 2021
55 votes
30 answers
2.5K views
How do I make the first letter of a string uppercase in JavaScript?

How do I make the first letter of a string uppercase, but not change the case of any of the other letters? For

avatar
Jefferey
0 1 0 9
asked 07 September, 2021
61 votes
30 answers
1.8K views
Setting "checked" for a checkbox with jQuery

I'd like to do something like this to tick a checkbox using jQuery: $(".myCheckBox").checked(true); or

avatar
Wilfredo
0 1 0 9
asked 07 September, 2021
56 votes
30 answers
457 views
How do you get a timestamp in JavaScript?

Something similar to Unix's timestamp, that is a single number that represents the current time and date.

avatar
Arline
0 1 0 9
asked 07 September, 2021
48 votes
30 answers
1.9K views
How do I check if an array includes a value in JavaScript?

What is the most concise and efficient way to find out if a JavaScript array contains a value? This is the onl

avatar
Omar
0 1 0 9
asked 07 September, 2021
61 votes
30 answers
1.7K views
How to create a GUID / UUID

I'm trying to create globally-unique identifiers in JavaScript. I'm not sure what routines are avai

avatar
Lynette
0 1 0 9
asked 07 September, 2021
60 votes
30 answers
1.4K views
How do I check whether a checkbox is checked in jQuery?

I need to check the checked property of a checkbox and perform an action based on the checked property using j

avatar
Charis
0 1 0 9
asked 07 September, 2021
54 votes
30 answers
2.6K views
How to replace all occurrences of a string in JavaScript

I have this string in my JavaScript code: "Test abc test test abc test test test abc test test abc" Doing: st

avatar
Santiago
0 1 0 9
asked 07 September, 2021
56 votes
30 answers
2.7K views
How to validate an email address in JavaScript

Is there a regular expression to verify an email address in JavaScript?

avatar
Leonardo
0 1 0 9
asked 07 September, 2021
60 votes
30 answers
950 views
For-each over an array in JavaScript

How can I loop through all the entries in an array using JavaScript? I thought it was something like this: f

avatar
Cortez
0 1 0 9
asked 07 September, 2021
60 votes
30 answers
1.8K views
57 votes
30 answers
1K views
What's the difference between using "let" and "var"?

ECMAScript 6 introduced the let statement. I've heard that it's described as a local variable, but I

avatar
Basil
0 1 0 9
asked 07 September, 2021