Public Questions

Ask Question

97 questions


0

Vote

3

Answers

75

View

All I want is to get the website URL. Not the URL as taken from a link. On the page loading, I need to be able to grab the full, current URL of the website and set it as a variable to do with as I ple

Jan 16

0

Vote

3

Answers

56

View

I have an object x. I'd like to copy it as object y, such that changes to y do not modify x. I realized that copying objects derived from built-in JavaScript objects will result in extra, unwanted pro

Jan 16

0

Vote

3

Answers

40

View

I saw this question, but I didn't see a JavaScript-specific example. Is there a simple string.Empty available in JavaScript, or is it just a case of checking for ""?

Jan 16

0

Vote

3

Answers

40

View

I'd like to round at most 2 decimal places, but only if necessary.Input:10 1.7777777 9.1Output:10 1.78 9.1How can I do this in JavaScript?

Jan 16

0

Vote

4

Answers

103

View

I have an array of JavaScript objects:var objs = [ { first_nom: 'Lazslo', last_nom: 'Jamf' }, { first_nom: 'Pig', last_nom: 'Bodine' }, { first_nom: 'Pirate', last_nom: 'Prent

Jan 13

0

Vote

4

Answers

47

View

I am looking for a JavaScript array insert method, in the style of:arr.insert(index, item)Preferably in jQuery, but any JavaScript implementation will do at this point.

Jan 13

0

Vote

4

Answers

35

View

I saw some code that seems to use an operator I don't recognize, in the form of two exclamation points, like so: !!. Can someone please tell me what this operator does?The context in which I saw this

Jan 13

0

Vote

4

Answers

31

View

After an AJAX request, sometimes my application may return an empty object, like:var a = {};How can I check whether that's the case?

Jan 13

0

Vote

4

Answers

38

View

What is the best way to copy text to the clipboard (multi-browser)?I have tried:function copyToClipboard(text) { if (window.clipboardData) { // Internet Explorer window.clipboardData.set

Jan 13

0

Vote

3

Answers

101

View

I have a bit of code where I am looping through all the select boxes on a page and binding a .hover event to them to do a bit of twiddling with their width on mouse on/off.This happens on page-ready a

0

Vote

3

Answers

97

View

I started using Google Apps Script yesterday and I'm struggling in running the code successfully when I attempt to get a range of cells instead of just one cell.This is the complete code, it will show

0

Vote

4

Answers

57

View

I am using the Scanner methods nextInt() and nextLine() for reading input.It looks like this:System.out.println("Enter numerical value"); int option; option = input.nextInt(); // Read numerical

Jan 10

0

Vote

4

Answers

98

View

What does ArrayIndexOutOfBoundsException mean and how do I get rid of it?Here is a code sample that triggers the exception:String[] names = { "tom", "bob", "harry" }; for (int i = 0; i <= names.le

Jan 10

0

Vote

4

Answers

34

View

I've been using the == operator in my program to compare all my strings so far. However, I ran into a bug, changed one of them into .equals() instead, and it fixed the bug.Is == bad? When should it an

Jan 10

0

Vote

4

Answers

54

View

What are Null Pointer Exceptions (java.lang.NullPointerException) and what causes them?What methods/tools can be used to determine the cause so that you stop the exception from causing the program to

Jan 10

0

Vote

4

Answers

93

View

Here is a piece of C++ code that shows some very peculiar behavior. For some strange reason, sorting the data (before the timed region) miraculously makes the loop almost six times faster.#include <

Jan 10

0

Vote

4

Answers

62

View

I have two Python dictionaries, and I want to write a single expression that returns these two dictionaries, merged (i.e. taking the union). The update() the method would be what I need if it returned

Jan 10

0

Vote

5

Answers

59

View

In Python, what are metaclasses and what do we use them for?

Jan 10

0

Vote

5

Answers

41

View

If Python does not have a ternary conditional operator, is it possible to simulate one using other language constructs?

Jan 10

0

Vote

3

Answers

57

View

Given the following code, what does the if __name__ == "__main__": do?# Threading example import time, thread def myfunction(string, sleeptime, lock, *args): while True: lock.acquire

Jan 10

0

Vote

5

Answers

37

View

What is the use of the yield keyword in Python? What does it do?For example, I'm trying to understand this code1:def _get_child_candidates(self, distance, min_dist, max_dist): if self._leftchild

0

Vote

5

Answers

42

View

The following are two methods of building a link that has the sole purpose of running JavaScript code. Which is better, in terms of functionality, page load speed, validation purposes, etc.?function m

Jan 10

0

Vote

4

Answers

26

View

Why does Google prepend while(1); to their (private) JSON responses?For example, here's a response while turning a calendar on and off in Google Calendar:while (1); [ ['u', [ ['smsSentFlag',

Jan 10

0

Vote

4

Answers

25

View

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

Jan 10

0

Vote

4

Answers

34

View

How do you get a date in JavaScript?Something similar to Unix's timestamp is a single number that represents the current time and date. Either as a number or a string.

Jan 10

0

Vote

4

Answers

31

View

How do I make the first letter of a string uppercase, but not change the case of any of the other letters?For example:"this is a test" → "This is a test""the Eiffel Tower" → "The Eiffel Tower""/in

0

Vote

4

Answers

59

View

What is the short and efficient way to find out if a JavaScript array contains a value?This is the only way I know to do it in JavaScript array:function contains(x, obj) { for (var i = 0; i < x

Jan 04

0

Vote

4

Answers

31

View

I need to check the checked property of a checkbox and perform an action based on the checked property using jQuery.For example, if the age checkbox is checked, then I need to show a textbox to enter

0

Vote

4

Answers

38

View

I have this string in my JavaScript code:"Test abc test test abc test test test abc test test abc"Doing:str = str.replace('abc', '');Seems to only remove the first occurrence of abc in the string abov

Dec 31

0

Vote

2

Answers

35

View

What's the best way to validate an email address in JavaScript with a regular expression?

Dec 31