itemId stringlengths 1 34 | itemType stringclasses 4
values | site stringclasses 4
values | scrapedAt timestamp[s]date 2026-08-03 00:21:25 2026-08-03 04:01:45 | tagName stringlengths 1 34 ⌀ | questionCount int64 2 2.53M ⌀ | hasSynonyms bool 2
classes | isModeratorOnly bool 1
class | isRequired bool 1
class | link stringlengths 32 258 | _run_id stringclasses 57
values | _dataset_id stringclasses 57
values | questionId int64 1 80M ⌀ | title stringlengths 15 150 ⌀ | score int64 -10 35.3k ⌀ | viewCount int64 6 16.7M ⌀ | answerCount int64 0 296 ⌀ | isAnswered bool 2
classes | hasAcceptedAnswer bool 2
classes | tags listlengths 1 6 ⌀ | createdAt timestamp[s]date 2008-08-01 04:18:04 2026-08-03 03:37:34 ⌀ | lastActivityAt timestamp[s]date 2008-10-30 09:20:18 2026-08-03 01:36:51 ⌀ | ownerDisplayName stringlengths 3 30 ⌀ | isClosed bool 2
classes | contentLicense stringclasses 3
values | acceptedAnswerId int64 4 80M ⌀ | ownerUserId int64 1 33M ⌀ | ownerReputation int64 1 1.53M ⌀ | userId int64 13 33M ⌀ | displayName stringclasses 897
values | reputation int64 1 1.53M ⌀ | userType stringclasses 3
values | lastAccessAt timestamp[s]date 2011-01-10 08:55:57 2026-08-03 03:38:13 ⌀ | goldBadges int64 0 895 ⌀ | silverBadges int64 0 9.32k ⌀ | bronzeBadges int64 0 9.36k ⌀ | reputationChangeMonth int64 -40 1.43k ⌀ | reputationChangeYear int64 -1,146 11.7k ⌀ | websiteUrl stringclasses 302
values | location stringclasses 279
values | acceptRate int64 17 100 ⌀ | answerId int64 1.13k 80M ⌀ | isAccepted bool 2
classes | bodyText stringlengths 31 24.4k ⌀ | bodyHtml stringlengths 39 34.9k ⌀ | answers listlengths 1 3 ⌀ | answersFetched int64 0 3 ⌀ |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1960473 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/1960473/get-all-unique-values-in-a-javascript-array-remove-duplicates | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 1,960,473 | Get all unique values in a JavaScript array (remove duplicates) | 2,926 | 3,759,314 | 94 | true | true | [
"javascript",
"unique",
"arrays"
] | 2009-12-25T04:28:23 | 2025-08-05T16:57:20 | Mottie | true | null | 14,438,954 | 145,346 | 86,809 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I have an array of numbers that I need to make sure are unique. I found the code snippet below on the Internet, and it works great until the array has a zero in it. I found this other script here on Stack Overflow that looks almost exactly like it, but it doesn't fail. How can I determine where the prototype script is ... | <p>I have an array of numbers that I need to make sure are unique. I found the code snippet below on the Internet, and it works great until the array has a zero in it. I found <a href="https://stackoverflow.com/questions/1890203">this other script</a> here on Stack Overflow that looks almost exactly like it, but it doe... | [
{
"answerId": 14438954,
"score": 4734,
"isAccepted": true,
"createdAt": "2013-01-21T12:46:24",
"ownerDisplayName": "TLindig",
"ownerUserId": 496587,
"bodyText": "With JavaScript 1.6 / ECMAScript 5 you can use the native filter method of an Array in the following way to get an array with ... | 1 |
1349404 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/1349404/generate-a-string-of-random-characters | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 1,349,404 | Generate a string of random characters | 2,915 | 3,161,342 | 94 | true | true | [
"javascript",
"string",
"random"
] | 2009-08-28T21:14:41 | 2025-10-28T16:37:44 | Tom Lehman | false | CC BY-SA 4.0 | 1,349,426 | 25,068 | 89,939 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I want a string of fixed length, composed of characters picked randomly from a set of characters e.g. [a-zA-Z0-9] . How can I do this with JavaScript? | <p>I want a string of fixed length, composed of characters picked randomly from a set of characters e.g. <code>[a-zA-Z0-9]</code>.</p>
<p>How can I do this with JavaScript?</p>
| [
{
"answerId": 1349426,
"score": 3768,
"isAccepted": true,
"createdAt": "2009-08-28T21:21:03",
"ownerDisplayName": "csharptest.net",
"ownerUserId": 164392,
"bodyText": "I think this will work for you: function makeid(length) { var result = ''; var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZa... | 2 |
351409 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/351409/how-to-append-something-to-an-array | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 351,409 | How to append something to an array? | 2,889 | 5,522,445 | 30 | true | true | [
"javascript",
"arrays",
"append"
] | 2008-12-09T00:20:05 | 2024-09-25T10:42:20 | interstar | false | CC BY-SA 3.0 | 351,421 | 8,482 | 27,616 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | How do I append an object (such as a string or number) to an array in JavaScript? | <p>How do I append an object (such as a string or number) to an array in JavaScript? </p>
| [
{
"answerId": 351421,
"score": 5430,
"isAccepted": true,
"createdAt": "2008-12-09T00:24:28",
"ownerDisplayName": "jdecuyper",
"ownerUserId": 296,
"bodyText": "Use the Array.prototype.push method to append values to the end of an array: // initialize array var arr = [ \"Hi\", \"Hello\", \... | 1 |
4059147 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/4059147/check-if-a-variable-is-a-string-in-javascript | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 4,059,147 | Check if a variable is a string in JavaScript | 2,883 | 3,097,422 | 35 | true | true | [
"javascript",
"string"
] | 2010-10-30T14:36:34 | 2025-12-09T14:31:20 | Olical | false | CC BY-SA 4.0 | 4,059,166 | 455,137 | 41,752 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | How can I determine whether a variable is a string or something else in JavaScript? | <p>How can I determine whether a variable is a string or something else in JavaScript?</p>
| [
{
"answerId": 9436948,
"score": 3027,
"isAccepted": false,
"createdAt": "2012-02-24T19:38:24",
"ownerDisplayName": "DRAX",
"ownerUserId": 1221512,
"bodyText": "This is what works for me: if (typeof myVar === 'string' || myVar instanceof String) // it's a string else // it's something els... | 2 |
492994 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/492994/compare-two-dates-with-javascript | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 492,994 | Compare two dates with JavaScript | 2,865 | 3,600,399 | 48 | true | true | [
"javascript",
"date",
"datetime",
"compare"
] | 2009-01-29T19:14:06 | 2024-03-08T11:22:50 | Alex | false | CC BY-SA 4.0 | 493,018 | 41,508 | 40,695 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | Can someone suggest a way to compare the values of two dates greater than, less than, and not in the past using JavaScript? The values will be coming from text boxes. | <p>Can someone suggest a way to compare the values of <strong>two dates</strong> greater than, less than, and not in the past using JavaScript? The values will be coming from text boxes.</p>
| [
{
"answerId": 493018,
"score": 3415,
"isAccepted": true,
"createdAt": "2009-01-29T19:20:10",
"ownerDisplayName": "moonshadow",
"ownerUserId": 11834,
"bodyText": "The Date object will do what you want - construct one for each date, then compare them using the > , < , <= or >= . The == , !... | 1 |
2901102 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/2901102/how-can-i-format-a-number-with-commas-as-thousands-separators | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 2,901,102 | How can I format a number with commas as thousands separators? | 2,781 | 2,340,658 | 53 | true | true | [
"javascript",
"formatting",
"numbers"
] | 2010-05-24T23:42:31 | 2026-02-21T12:00:43 | Elias Zamaria | false | CC BY-SA 4.0 | 2,901,298 | 28,324 | 101,964 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I am trying to print an integer in JavaScript with commas as thousands separators. For example, I want to show the number 1234567 as "1,234,567". How would I go about doing this? Here is how I am doing it: function numberWithCommas(x) { x = x.toString(); var pattern = /(-?\d+)(\d{3})/; while (pattern.test(x)) x = x.rep... | <p>I am trying to print an integer in JavaScript with commas as thousands separators. For example, I want to show the number 1234567 as "1,234,567". How would I go about doing this?</p>
<p>Here is how I am doing it:</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="f... | [
{
"answerId": 2901298,
"score": 3957,
"isAccepted": true,
"createdAt": "2010-05-25T00:40:59",
"ownerDisplayName": "Elias Zamaria",
"ownerUserId": 28324,
"bodyText": "I used the idea from Kerry's answer , but I simplified it since I was just looking for something simple for my specific pu... | 2 |
5404839 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/5404839/how-do-i-refresh-a-page-using-javascript | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 5,404,839 | How do I refresh a page using JavaScript? | 2,764 | 3,226,822 | 20 | true | true | [
"javascript",
"jquery",
"refresh",
"reload"
] | 2011-03-23T11:55:31 | 2026-04-28T08:57:51 | luca | false | CC BY-SA 4.0 | 5,404,869 | 505,762 | 37,252 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | How do I refresh a page using JavaScript? | <p>How do I refresh a page using JavaScript?</p>
| [
{
"answerId": 5404869,
"score": 4209,
"isAccepted": true,
"createdAt": "2011-03-23T11:57:51",
"ownerDisplayName": "Roy",
"ownerUserId": 333426,
"bodyText": "Use location.reload() . For example, to reload whenever an element with id=\"something\" is clicked: $('#something').click(function... | 1 |
6677035 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/6677035/scroll-to-an-element-with-jquery | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 6,677,035 | Scroll to an element with jQuery | 2,732 | 3,248,505 | 33 | true | true | [
"javascript",
"jquery",
"scroll"
] | 2011-07-13T09:49:44 | 2023-08-15T10:19:38 | DiegoP. | false | CC BY-SA 4.0 | 6,677,069 | 735,997 | 45,875 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I have this input element: <input type="text" class="textfield" value="" id="subject" name="subject"> Then I have some other elements, like other tag's & <textarea> tag's, etc... When the user clicks on the <input id="#subject"> , the page should scroll to the page's last element, and it should do so with a nice animat... | <p>I have this <code>input</code> element:</p>
<pre><code> <input type="text" class="textfield" value="" id="subject" name="subject">
</code></pre>
<p>Then I have some other elements, like other tag's & <code><textarea></code> tag's, etc...</p>
<p>When... | [
{
"answerId": 6677069,
"score": 4557,
"isAccepted": true,
"createdAt": "2011-07-13T09:52:36",
"ownerDisplayName": "Steve",
"ownerUserId": 343088,
"bodyText": "Assuming you have a button with the id button , try this example: $(\"#button\").click(function() { $([document.documentElement, ... | 1 |
2647867 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/2647867/how-can-i-determine-if-a-variable-is-undefined-or-null | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 2,647,867 | How can I determine if a variable is 'undefined' or 'null'? | 2,718 | 3,555,136 | 33 | true | true | [
"javascript",
"jquery",
"variables",
"null",
"undefined"
] | 2010-04-15T18:12:16 | 2023-12-04T17:15:49 | sadmicrowave | false | CC BY-SA 4.0 | 2,647,888 | 281,488 | 41,090 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | How do I determine if a variable is undefined or null ? My code is as follows: var EmpName = $("div#esd-names div#name").attr('class'); if(EmpName == 'undefined'){ // DO SOMETHING }; <div id="esd-names"> <div id="name"></div> </div> But when I do this, the JavaScript interpreter halts execution. | <p>How do I determine if a variable is <code>undefined</code> or <code>null</code>?</p>
<p>My code is as follows:</p>
<pre class="lang-js prettyprint-override"><code>var EmpName = $("div#esd-names div#name").attr('class');
if(EmpName == 'undefined'){
// DO SOMETHING
};
</code></pre>
<pre class="lang-html pr... | [
{
"answerId": 2647888,
"score": 3583,
"isAccepted": true,
"createdAt": "2010-04-15T18:14:35",
"ownerDisplayName": "Sarfraz",
"ownerUserId": 139459,
"bodyText": "You can use the qualities of the abstract equality operator to do this: if (variable == null){ // your code here. } Because nul... | 1 |
48270127 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/48270127/can-a-1-a-2-a-3-ever-evaluate-to-true | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 48,270,127 | Can (a== 1 && a ==2 && a==3) ever evaluate to true? | 2,703 | 435,234 | 28 | true | true | [
"javascript",
"ecmascript-6"
] | 2018-01-15T20:20:47 | 2026-01-27T22:01:28 | Dimpu Aravind Buddha | false | CC BY-SA 4.0 | 48,270,314 | 1,165,332 | 9,895 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | Moderator note: Please resist the urge to edit the code or remove this notice. The pattern of whitespace may be part of the question and therefore should not be tampered with unnecessarily. If you are in the "whitespace is insignificant" camp, you should be able to accept the code as is. How is it ever possible that (a... | <blockquote>
<p><strong>Moderator note:</strong> Please resist the urge to edit the code or remove this notice. The pattern of whitespace may be part of the question and therefore should not be tampered with unnecessarily. If you are in the "whitespace is insignificant" camp, you should be able to accept the ... | [
{
"answerId": 48270314,
"score": 3507,
"isAccepted": true,
"createdAt": "2018-01-15T20:35:15",
"ownerDisplayName": "user400654",
"ownerUserId": 400654,
"bodyText": "If you take advantage of how == works , you could simply create an object with a custom toString (or valueOf ) function tha... | 1 |
901115 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 901,115 | How can I get query string values in JavaScript? | 2,693 | 5,522,046 | 73 | true | true | [
"javascript",
"url",
"plugins",
"query-string"
] | 2009-05-23T08:10:48 | 2023-06-06T10:08:34 | Subliminal Hash | false | CC BY-SA 3.0 | 901,144 | 49,742 | 13,762 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | Is there a plugin-less way of retrieving query string values via jQuery (or without)? If so, how? If not, is there a plugin which can do so? | <p>Is there a plugin-less way of retrieving <a href="http://en.wikipedia.org/wiki/Query_string" rel="nofollow noreferrer">query string</a> values via jQuery (or without)? </p>
<p>If so, how? If not, is there a plugin which can do so?</p>
| [
{
"answerId": 901144,
"score": 10677,
"isAccepted": true,
"createdAt": "2009-05-23T08:35:46",
"ownerDisplayName": "Artem Barger",
"ownerUserId": 104014,
"bodyText": "Use URLSearchParams to get parameters from the query string. For example: const urlParams = new URLSearchParams(window.loc... | 1 |
894860 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/894860/set-a-default-parameter-value-for-a-javascript-function | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 894,860 | Set a default parameter value for a JavaScript function | 2,691 | 1,500,039 | 30 | true | true | [
"javascript",
"function",
"parameters",
"arguments",
"default-parameters"
] | 2009-05-21T20:07:17 | 2025-08-14T03:36:04 | Tilendor | false | CC BY-SA 4.0 | 894,877 | 1,470 | 49,013 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I would like a JavaScript function to have optional arguments which I set a default on, which get used if the value isn't defined (and ignored if the value is passed). In Ruby you can do it like this: def read_file(file, delete_after = false) # code end Does this work in JavaScript? function read_file(file, delete_afte... | <p>I would like a JavaScript function to have optional arguments which I set a default on, which get used if the value isn't defined (and ignored if the value is passed). In Ruby you can do it like this:</p>
<pre><code>def read_file(file, delete_after = false)
# code
end
</code></pre>
<p>Does this work in JavaScrip... | [
{
"answerId": 894877,
"score": 3597,
"isAccepted": true,
"createdAt": "2009-05-21T20:10:52",
"ownerDisplayName": "Tom Ritter",
"ownerUserId": 8435,
"bodyText": "From ES6/ES2015 , default parameters are in the language specification. function read_file(file, delete_after = false) { // Cod... | 1 |
171027 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/171027/adding-a-table-row-in-jquery | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 171,027 | Adding a table row in jQuery | 2,677 | 2,059,439 | 42 | true | true | [
"javascript",
"jquery",
"html-table"
] | 2008-10-04T21:33:10 | 2022-08-16T15:48:14 | Darryl Hein | false | CC BY-SA 4.0 | 171,049 | 5,441 | 145,595 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I'm using jQuery to add an additional row to a table as the last row. I have done it this way: $('#myTable').append('<tr><td>my data</td><td>more data</td></tr>'); Are there limitations to what you can add to a table like this (such as inputs, selects, number of rows)? Is there a different way to do it? | <p>I'm using jQuery to add an additional row to a table as the last row.</p>
<p>I have done it this way:</p>
<pre><code>$('#myTable').append('<tr><td>my data</td><td>more data</td></tr>');
</code></pre>
<p>Are there limitations to what you can add to a table like this (such as inputs... | null | 0 |
952924 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/952924/how-do-i-chop-slice-trim-off-last-character-in-string-using-javascript | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 952,924 | How do I chop/slice/trim off last character in string using Javascript? | 2,624 | 2,662,110 | 26 | true | true | [
"javascript",
"slice",
"trim"
] | 2009-06-04T20:31:53 | 2025-02-01T21:44:53 | Phill Pafford | false | CC BY-SA 4.0 | 952,945 | 93,966 | 85,658 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I have a string, 12345.00 , and I would like it to return 12345.0 . I have looked at trim , but it looks like it is only trimming whitespace and slice which I don't see how this would work. Any suggestions? | <p>I have a string, <code>12345.00</code>, and I would like it to return <code>12345.0</code>.</p>
<p>I have looked at <code>trim</code>, but it looks like it is only trimming whitespace and <code>slice</code> which I don't see how this would work. Any suggestions?</p>
| [
{
"answerId": 952945,
"score": 4054,
"isAccepted": true,
"createdAt": "2009-06-04T20:35:48",
"ownerDisplayName": "Jon Erickson",
"ownerUserId": 1950,
"bodyText": "You can use the substring function: let str = \"12345.00\"; str = str.substring(0, str.length - 1); console.log(str); This is... | 1 |
4959975 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/4959975/generate-random-number-between-two-numbers-in-javascript | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 4,959,975 | Generate random number between two numbers in JavaScript | 2,617 | 2,730,328 | 34 | true | true | [
"javascript",
"random"
] | 2011-02-10T16:41:22 | 2024-06-03T13:50:18 | Mirgorod | false | CC BY-SA 4.0 | 4,960,020 | 568,975 | 32,937 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | Is there a way to generate a random number in a specified range with JavaScript ? For example : a specified range from 1 to 6 were the random number could be either 1, 2, 3, 4, 5, or 6 . | <p>Is there a way to generate a <em>random number</em> in a <em>specified range</em> with JavaScript ?</p>
<p><strong>For example</strong>: a specified range from <em>1 to 6</em> were the random number could be either <em>1, 2, 3, 4, 5, or 6</em>.</p>
| [
{
"answerId": 7228322,
"score": 3446,
"isAccepted": false,
"createdAt": "2011-08-29T09:25:57",
"ownerDisplayName": "Francisc",
"ownerUserId": 383148,
"bodyText": "function randomIntFromInterval(min, max) { // min and max included return Math.floor(Math.random() * (max - min + 1) + min); ... | 2 |
1133770 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/1133770/how-can-i-convert-a-string-to-an-integer-in-javascript | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 1,133,770 | How can I convert a string to an integer in JavaScript? | 2,597 | 2,901,121 | 32 | true | true | [
"javascript",
"string",
"integer",
"data-conversion"
] | 2009-07-15T20:22:48 | 2025-10-05T17:13:52 | null | false | CC BY-SA 4.0 | 1,133,814 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | How do I convert a string to an integer in JavaScript? | <p>How do I convert a string to an integer in JavaScript?</p>
| [
{
"answerId": 1133814,
"score": 3123,
"isAccepted": true,
"createdAt": "2009-07-15T20:28:48",
"ownerDisplayName": "Nosredna",
"ownerUserId": 61027,
"bodyText": "The simplest way would be to use the native Number function: var x = Number(\"1000\") If that doesn't work for you, then there ... | 1 |
1414365 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/1414365/disable-enable-an-input-with-jquery | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 1,414,365 | Disable/enable an input with jQuery? | 2,595 | 2,744,768 | 19 | true | true | [
"javascript",
"jquery",
"html-input",
"disabled-input"
] | 2009-09-12T05:21:54 | 2023-03-29T18:57:52 | omg | false | CC BY-SA 4.0 | 1,414,366 | 104,015 | 141,112 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | $input.disabled = true; or $input.disabled = "disabled"; Which is the standard way? And, conversely, how do you enable a disabled input? | <pre><code>$input.disabled = true;
</code></pre>
<p>or </p>
<pre><code>$input.disabled = "disabled";
</code></pre>
<p>Which is the standard way? And, conversely, how do you enable a disabled input?</p>
| [
{
"answerId": 1414366,
"score": 4170,
"isAccepted": true,
"createdAt": "2009-09-12T05:23:34",
"ownerDisplayName": "gnarf",
"ownerUserId": 91914,
"bodyText": "jQuery 1.6+ To change the disabled property you should use the .prop() function. $(\"input\").prop('disabled', true); $(\"input\")... | 1 |
18082 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/18082/validate-decimal-numbers-in-javascript-isnumeric | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 18,082 | Validate decimal numbers in JavaScript - IsNumeric() | 2,574 | 1,590,504 | 52 | true | true | [
"javascript",
"validation",
"numbers"
] | 2008-08-20T14:21:13 | 2024-08-13T12:14:03 | Michael Haren | false | CC BY-SA 3.0 | 1,830,844 | 29 | 108,790 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | What's the cleanest, most effective way to validate decimal numbers in JavaScript? Bonus points for: Clarity. Solution should be clean and simple. Cross-platform. Test cases: 01. IsNumeric('-1') => true 02. IsNumeric('-1.5') => true 03. IsNumeric('0') => true 04. IsNumeric('0.42') => true 05. IsNumeric('.42') => true 0... | <p>What's the cleanest, most effective way to validate decimal numbers in JavaScript?</p>
<p>Bonus points for:</p>
<ol>
<li>Clarity. Solution should be clean and simple.</li>
<li>Cross-platform.</li>
</ol>
<p>Test cases:</p>
<pre><code>01. IsNumeric('-1') => true
02. IsNumeric('-1.5') => true
03. IsNu... | [
{
"answerId": 1830844,
"score": 3005,
"isAccepted": true,
"createdAt": "2009-12-02T05:36:22",
"ownerDisplayName": "Christian C. Salvadó",
"ownerUserId": 5445,
"bodyText": "Some time ago I had to implement an IsNumeric function, to find out if a variable contained a numeric value, regardl... | 1 |
1527803 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/1527803/generating-random-whole-numbers-in-javascript-in-a-specific-range | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 1,527,803 | Generating random whole numbers in JavaScript in a specific range | 2,572 | 2,145,086 | 42 | true | true | [
"javascript",
"random",
"integer"
] | 2009-10-06T20:05:41 | 2025-09-09T17:03:38 | zacharyliu | false | CC BY-SA 4.0 | 1,527,820 | 133,211 | 26,418 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | How can I generate random whole numbers between two specified variables in JavaScript, e.g. x = 4 and y = 8 would output any of 4, 5, 6, 7, 8 ? | <p>How can I generate random whole numbers between two specified variables in JavaScript, e.g. <code>x = 4</code> and <code>y = 8</code> would output any of <code>4, 5, 6, 7, 8</code>?</p>
| [
{
"answerId": 1527820,
"score": 4925,
"isAccepted": true,
"createdAt": "2009-10-06T20:08:19",
"ownerDisplayName": "Ionuț G. Stan",
"ownerUserId": 58808,
"bodyText": "There are some examples on the Mozilla Developer Network page: /** * Returns a random number between min (inclusive) and m... | 1 |
9229645 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/9229645/remove-duplicate-values-from-a-javascript-array | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 9,229,645 | Remove duplicate values from a JavaScript array | 2,550 | 3,431,992 | 51 | true | true | [
"javascript",
"jquery",
"arrays",
"duplicates",
"unique"
] | 2012-02-10T14:53:22 | 2025-12-25T19:32:38 | kramden88 | false | CC BY-SA 4.0 | 9,229,932 | 814,908 | 25,779 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I have a very simple JavaScript array that may or may not contain duplicates. var names = ["Mike","Matt","Nancy","Adam","Jenny","Nancy","Carl"]; I need to remove the duplicates and put the unique values in a new array. I could point to all the code that I've tried but I think it's useless because they don't work. I acc... | <p>I have a very simple JavaScript array that may or may not contain duplicates.</p>
<pre><code>var names = ["Mike","Matt","Nancy","Adam","Jenny","Nancy","Carl"];
</code></pre>
<p>I need to remove the duplicates and put the unique values in a new arr... | [
{
"answerId": 9229821,
"score": 6306,
"isAccepted": false,
"createdAt": "2012-02-10T15:05:41",
"ownerDisplayName": "georg",
"ownerUserId": 989121,
"bodyText": "TL;DR Using the Set constructor and the spread syntax : uniq = [...new Set(array)]; ( Note that var uniq will be an array... new... | 1 |
1643227 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/1643227/get-selected-text-from-a-drop-down-list-select-box-using-jquery | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 1,643,227 | Get selected text from a drop-down list (select box) using jQuery | 2,550 | 2,421,756 | 35 | true | true | [
"javascript",
"jquery",
"dom",
"drop-down-menu",
"jquery-selectors"
] | 2009-10-29T12:02:09 | 2021-10-20T14:48:08 | haddar | false | CC BY-SA 4.0 | 1,643,247 | 170,231 | 25,715 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | How can I get the selected text (not the selected value) from a drop-down list in jQuery? | <p>How can I get the selected text (not the selected value) from a <strong>drop-down list</strong> in jQuery?</p>
| [
{
"answerId": 1643247,
"score": 4049,
"isAccepted": true,
"createdAt": "2009-10-29T12:05:38",
"ownerDisplayName": "rahul",
"ownerUserId": 47738,
"bodyText": "$(\"#yourdropdownid option:selected\").text();"
}
] | 1 |
149055 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/149055/how-to-format-numbers-as-currency-strings | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 149,055 | How to format numbers as currency strings? | 2,527 | 2,963,574 | 67 | true | true | [
"javascript",
"formatting",
"currency",
"number-formatting"
] | 2008-09-29T15:00:28 | 2025-09-26T17:14:08 | Daniel Magliola | false | CC BY-SA 4.0 | 149,150 | 3,314 | 32,802 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I would like to format a price in JavaScript. I'd like a function which takes a float as an argument and returns a string formatted like this: $ 2,500.00 How can I do this? | <p>I would like to format a price in JavaScript. I'd like a function which takes a <code>float</code> as an argument and returns a <code>string</code> formatted like this:</p>
<pre><code>$ 2,500.00
</code></pre>
<p>How can I do this?</p>
| [
{
"answerId": 16233919,
"score": 2864,
"isAccepted": false,
"createdAt": "2013-04-26T10:09:56",
"ownerDisplayName": "aross",
"ownerUserId": 1000608,
"bodyText": "Intl.NumberFormat JavaScript has a number formatter (part of the Internationalization API). // Create our number formatter. co... | 1 |
5874652 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/5874652/prop-vs-attr | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 5,874,652 | .prop() vs .attr() | 2,514 | 750,952 | 18 | true | true | [
"javascript",
"jquery",
"dom",
"attr",
"prop"
] | 2011-05-03T19:33:28 | 2023-12-06T01:53:53 | Naftali | false | CC BY-SA 3.0 | 5,876,747 | 561,731 | 146,679 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | So jQuery 1.6 has the new function prop() . $(selector).click(function(){ //instead of: this.getAttribute('style'); //do i use: $(this).prop('style'); //or: $(this).attr('style'); }) or in this case do they do the same thing? And if I do have to switch to using prop() , all the old attr() calls will break if i switch t... | <p>So <a href="http://api.jquery.com/category/version/1.6/" rel="noreferrer">jQuery 1.6</a> has the new function <a href="http://api.jquery.com/prop/" rel="noreferrer"><code>prop()</code></a>.</p>
<pre><code>$(selector).click(function(){
//instead of:
this.getAttribute('style');
//do i use:
$(this).pro... | null | 0 |
2067472 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/2067472/what-is-jsonp-and-why-was-it-created | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 2,067,472 | What is JSONP, and why was it created? | 2,493 | 631,645 | 10 | true | true | [
"javascript",
"json",
"jsonp",
"terminology"
] | 2010-01-14T20:53:48 | 2023-06-16T19:22:45 | Cheeso | false | CC BY-SA 4.0 | 2,067,584 | 48,082 | 193,523 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I understand JSON, but not JSONP. Wikipedia's document on JSON is (was) the top search result for JSONP. It says this: JSONP or "JSON with padding" is a JSON extension wherein a prefix is specified as an input argument of the call itself. Huh? What call? That doesn't make any sense to me. JSON is a data format. There's... | <p>I understand JSON, but not JSONP. <a href="http://en.wikipedia.org/wiki/JSON" rel="noreferrer">Wikipedia's document on JSON</a> is (was) the top search result for JSONP. It says this:</p>
<blockquote>
<p>JSONP or "JSON with padding" is a JSON extension wherein a prefix is specified as an input argument of the cal... | [
{
"answerId": 2067584,
"score": 2324,
"isAccepted": true,
"createdAt": "2010-01-14T21:08:08",
"ownerDisplayName": "Jerod Venema",
"ownerUserId": 25330,
"bodyText": "It's actually not too complicated... Say you're on domain example.com , and you want to make a request to domain example.ne... | 1 |
3746725 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/3746725/how-to-create-an-array-containing-1-n | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 3,746,725 | How to create an array containing 1...N | 2,483 | 2,848,123 | 82 | true | true | [
"javascript",
"arrays",
"range"
] | 2010-09-19T17:34:17 | 2026-04-15T06:43:09 | Godders | false | CC BY-SA 4.0 | 3,746,797 | 305,844 | 25,306 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I'm looking for any alternatives to the below for creating a JavaScript array containing 1 through to N where N is only known at runtime. var foo = []; for (var i = 1; i <= N; i++) { foo.push(i); } To me it feels like there should be a way of doing this without the loop. | <p>I'm looking for any alternatives to the below for creating a JavaScript array containing 1 through to N where N is only known at runtime.</p>
<pre><code>var foo = [];
for (var i = 1; i <= N; i++) {
foo.push(i);
}
</code></pre>
<p>To me it feels like there should be a way of doing this without the loop.</p>
| [
{
"answerId": 33352604,
"score": 3984,
"isAccepted": false,
"createdAt": "2015-10-26T18:03:26",
"ownerDisplayName": "Niko Ruotsalainen",
"ownerUserId": 4079317,
"bodyText": "In ES6 using Array from() and keys() methods. Array.from(Array(10).keys()) //=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] Sho... | 1 |
5113374 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/5113374/javascript-check-if-variable-exists-is-defined-initialized | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 5,113,374 | JavaScript check if variable exists (is defined/initialized) | 2,479 | 2,730,843 | 31 | true | true | [
"javascript",
"function",
"variables",
"initialization",
"undefined"
] | 2011-02-25T03:44:47 | 2022-12-11T14:00:19 | samliew | false | CC BY-SA 4.0 | 6,509,422 | 584,192 | 79,622 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | Which method of checking if a variable has been initialized is better/correct? (Assuming the variable could hold anything (string, int, object, function, etc.)) if (elem) { // or !elem or if (typeof elem !== 'undefined') { or if (elem != null) { | <p>Which method of checking if a variable has been initialized is better/correct?
(Assuming the variable could hold anything (string, int, object, function, etc.))</p>
<pre><code>if (elem) { // or !elem
</code></pre>
<p>or</p>
<pre><code>if (typeof elem !== 'undefined') {
</code></pre>
<p>or</p>
<pre><code>if (elem != ... | [
{
"answerId": 519157,
"score": 4002,
"isAccepted": false,
"createdAt": "2009-02-06T04:56:55",
"ownerDisplayName": "Jim Puls",
"ownerUserId": 6010,
"bodyText": "You want the typeof operator . Specifically: if (typeof variable !== 'undefined') { // the variable is defined }"
}
] | 1 |
610406 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/610406/javascript-equivalent-to-printf-string-format | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 610,406 | JavaScript equivalent to printf/String.Format | 2,477 | 2,567,710 | 62 | true | true | [
"javascript",
"printf",
"string.format"
] | 2009-03-04T12:53:02 | 2025-08-05T21:13:43 | Chris S | false | CC BY-SA 4.0 | 610,415 | 21,574 | 65,642 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I'm looking for a good JavaScript equivalent of the C/PHP printf() or for C#/Java programmers, String.Format() ( IFormatProvider for .NET). My basic requirement is a thousand separator format for numbers for now, but something that handles lots of combinations (including dates) would be good. I realize Microsoft's Ajax... | <p>I'm looking for a good JavaScript equivalent of the C/PHP <code>printf()</code> or for C#/Java programmers, <code>String.Format()</code> (<code>IFormatProvider</code> for .NET).</p>
<p>My basic requirement is a thousand separator format for numbers for now, but something that handles lots of combinations (including... | null | 0 |
3437786 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/3437786/get-the-size-of-the-screen-current-web-page-and-browser-window | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 3,437,786 | Get the size of the screen, current web page and browser window | 2,469 | 2,287,104 | 22 | true | true | [
"javascript",
"html",
"jquery",
"layout",
"cross-browser"
] | 2010-08-09T06:28:58 | 2024-10-12T05:29:17 | turtledove | false | CC BY-SA 4.0 | 3,437,825 | 408,393 | 25,984 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | How can I get windowWidth , windowHeight , pageWidth , pageHeight , screenWidth , screenHeight , pageX , pageY , screenX , screenY which will work in all major browsers? | <p>How can I get <code>windowWidth</code>, <code>windowHeight</code>, <code>pageWidth</code>, <code>pageHeight</code>, <code>screenWidth</code>, <code>screenHeight</code>, <code>pageX</code>, <code>pageY</code>, <code>screenX</code>, <code>screenY</code> which will work in all major browsers?</p>
<p><img src="https://... | null | 0 |
799981 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/799981/document-ready-equivalent-without-jquery | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 799,981 | $(document).ready equivalent without jQuery | 2,464 | 1,391,610 | 40 | true | true | [
"javascript",
"jquery",
"pageload"
] | 2009-04-28T21:51:11 | 2026-02-14T02:54:58 | FlySwat | false | CC BY-SA 4.0 | 800,010 | 1,965 | 176,523 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I have a script that uses $(document).ready , but it doesn't use anything else from jQuery. I'd like to lighten it up by removing the jQuery dependency. How can I implement my own $(document).ready functionality without using jQuery? I know that using window.onload will not be the same, as window.onload fires after all... | <p>I have a script that uses <code>$(document).ready</code>, but it doesn't use anything else from jQuery. I'd like to lighten it up by removing the jQuery dependency.</p>
<p>How can I implement my own <code>$(document).ready</code> functionality without using jQuery? I know that using <code>window.onload</code> will... | null | 0 |
1085801 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/1085801/get-selected-value-in-dropdown-list-using-javascript | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 1,085,801 | Get selected value in dropdown list using JavaScript | 2,442 | 6,117,244 | 31 | true | true | [
"javascript",
"html-select"
] | 2009-07-06T07:25:06 | 2023-12-28T14:39:58 | Fire Hand | false | CC BY-SA 4.0 | 1,085,810 | 127,986 | 26,586 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | How do I get the selected value from a dropdown list using JavaScript? <form> <select id="ddlViewBy"> <option value="1">test1</option> <option value="2" selected="selected">test2</option> <option value="3">test3</option> </select> </form> | <p>How do I get the selected value from a dropdown list using JavaScript?</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code><form>
<select id="ddlViewBy">
... | [
{
"answerId": 1085810,
"score": 3844,
"isAccepted": true,
"createdAt": "2009-07-06T07:29:43",
"ownerDisplayName": "Paolo Bergantino",
"ownerUserId": 16417,
"bodyText": "Given a select element that looks like this: <select id=\"ddlViewBy\"> <option value=\"1\">test1</option> <option value... | 1 |
8073673 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/8073673/how-can-i-add-new-array-elements-at-the-beginning-of-an-array-in-javascript | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 8,073,673 | How can I add new array elements at the beginning of an array in JavaScript? | 2,437 | 1,754,189 | 12 | true | true | [
"javascript",
"arrays"
] | 2011-11-10T00:35:22 | 2025-04-15T21:58:06 | Moon | false | CC BY-SA 4.0 | 8,073,687 | 309,343 | 35,645 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I have a need to add or prepend elements at the beginning of an array. For example, if my array looks like below: [23, 45, 12, 67] And the response from my AJAX call is 34 , I want the updated array to be like the following: [34, 23, 45, 12, 67] Currently I am planning to do it like this: var newArray = []; newArray.pu... | <p>I have a need to add or prepend elements at the beginning of an array.</p>
<p>For example, if my array looks like below:</p>
<pre><code>[23, 45, 12, 67]
</code></pre>
<p>And the response from my AJAX call is <code>34</code>, I want the updated array to be like the following:</p>
<pre><code>[34, 23, 45, 12, 67]
</cod... | [
{
"answerId": 8073687,
"score": 4069,
"isAccepted": true,
"createdAt": "2011-11-10T00:37:49",
"ownerDisplayName": "user229044",
"ownerUserId": 229044,
"bodyText": "Use unshift . It's like push , except it adds elements to the beginning of the array instead of the end. unshift / push - ad... | 1 |
306583 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/306583/how-to-get-the-children-of-the-this-selector | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 306,583 | How to get the children of the $(this) selector? | 2,423 | 1,997,844 | 19 | true | true | [
"javascript",
"jquery",
"jquery-selectors"
] | 2008-11-20T19:44:05 | 2024-07-31T09:36:31 | Alex | false | CC BY-SA 4.0 | 306,904 | 16,974 | 26,644 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I have a layout similar to this, and would like to use a jQuery selector to select the child img inside the div on click. <div id="..."> <img src="..."> </div> To get the div , I've got this selector: $(this) How can I get the child img using a selector? | <p>I have a layout similar to this, and would like to use a <code>jQuery</code> selector to select the child <code>img</code> inside the <code>div</code> on click.</p>
<pre class="lang-html prettyprint-override"><code><div id="...">
<img src="...">
</div>
</code></pre>
<p>To get ... | [
{
"answerId": 306904,
"score": 2986,
"isAccepted": true,
"createdAt": "2008-11-20T21:27:29",
"ownerDisplayName": "Simon",
"ownerUserId": 33036,
"bodyText": "The jQuery constructor accepts a 2nd parameter called context which can be used to override the context of the selection. jQuery(\"... | 1 |
287903 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/287903/how-can-i-guarantee-that-my-enums-definition-doesnt-change-in-javascript | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 287,903 | How can I guarantee that my enums definition doesn't change in JavaScript? | 2,396 | 1,289,445 | 50 | true | true | [
"javascript"
] | 2008-11-13T19:09:06 | 2023-09-11T11:28:22 | David Citron | false | CC BY-SA 4.0 | 5,040,502 | 5,309 | 43,669 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | Would the following make the objects fulfil all characteristics that enums have in JavaScript? Something like: my.namespace.ColorEnum = { RED : 0, GREEN : 1, BLUE : 2 } // later on if(currentColor == my.namespace.ColorEnum.RED) { // whatever } Or is there some other way I can do this? | <p>Would the following make the objects fulfil all characteristics that enums have in JavaScript? Something like:</p>
<pre class="lang-js prettyprint-override"><code>my.namespace.ColorEnum = {
RED : 0,
GREEN : 1,
BLUE : 2
}
// later on
if(currentColor == my.namespace.ColorEnum.RED) {
// whatever
}
</code></p... | null | 0 |
31079081 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/31079081/how-can-i-programmatically-navigate-using-react-router | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 31,079,081 | How can I programmatically navigate using React Router? | 2,376 | 1,817,076 | 50 | true | true | [
"javascript",
"reactjs",
"react-router"
] | 2015-06-26T17:38:51 | 2026-02-06T10:14:42 | George Mauer | false | CC BY-SA 4.0 | 42,121,109 | 5,056 | 123,156 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | With React Router , I can use the Link element to create links which are natively handled by React Router. I see internally it calls this.context.transitionTo(...) . I want to do navigation. Not from a link, but from a dropdown selection (as an example). How can I do this in code? What is this.context ? I saw the Navig... | <p>With <a href="https://reactrouter.com/" rel="noreferrer">React Router</a>, I can use the <code>Link</code> element to create links which are natively handled by React Router.</p>
<p>I see internally it calls <code>this.context.transitionTo(...)</code>.</p>
<p>I want to do navigation. Not from a link, but from a drop... | [
{
"answerId": 42121109,
"score": 2637,
"isAccepted": true,
"createdAt": "2017-02-08T18:39:41",
"ownerDisplayName": "Paul S",
"ownerUserId": 444829,
"bodyText": "React Router v6.6.1 with useNavigate The useHistory() hook is now deprecated. If you are using React Router 6, the proper way t... | 1 |
8511281 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/8511281/check-if-a-value-is-an-object-in-javascript | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 8,511,281 | Check if a value is an object in JavaScript | 2,337 | 2,528,212 | 59 | true | true | [
"javascript",
"types",
"javascript-objects"
] | 2011-12-14T20:35:47 | 2025-01-03T16:20:55 | Danny Fox | false | CC BY-SA 4.0 | 8,511,332 | 1,091,828 | 41,169 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | How do you check if a value is an object in JavaScript? | <p>How do you check if a value is an object in JavaScript?</p>
| [
{
"answerId": 8511350,
"score": 2624,
"isAccepted": false,
"createdAt": "2011-12-14T20:40:51",
"ownerDisplayName": "Chuck",
"ownerUserId": 50742,
"bodyText": "If typeof x === 'object' , x is an object (except a function) or null . If you want null , arrays, and functions to be excluded, ... | 1 |
242813 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/242813/are-double-quotes-and-single-quotes-interchangeable-for-string-literals-in-javas | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 242,813 | Are double quotes and single quotes interchangeable for string literals in JavaScript? | 2,333 | 761,574 | 24 | true | true | [
"javascript",
"string"
] | 2008-10-28T10:34:35 | 2025-11-01T04:02:18 | aemkei | false | CC BY-SA 4.0 | 242,833 | 28,150 | 11,235 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | Consider the following two alternatives: console.log("double"); console.log('single'); The former uses double quotes around the string, whereas the latter uses single quotes around the string. I see more and more JavaScript libraries out there using single quotes when handling strings. Are these two usages interchangea... | <p>Consider the following two alternatives:</p>
<ul>
<li><code>console.log("double");</code></li>
<li><code>console.log('single');</code></li>
</ul>
<p>The former uses double quotes around the string, whereas the latter uses single quotes around the string.</p>
<p>I see more and more JavaScript libraries out ... | null | 0 |
2641347 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/2641347/short-circuit-array-foreach-like-calling-break | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 2,641,347 | Short circuit Array.forEach like calling break | 2,249 | 1,908,152 | 32 | true | true | [
"javascript",
"arrays",
"foreach"
] | 2010-04-14T21:57:31 | 2025-09-19T09:04:15 | Scott Klarenbach | false | CC BY-SA 4.0 | 2,641,374 | 140,811 | 38,965 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | [1,2,3].forEach(function(el) { if(el === 1) break; }); How can I do this using the new forEach method in JavaScript? I've tried return; , return false; and break . break crashes and return does nothing but continue iteration. | <pre><code>[1,2,3].forEach(function(el) {
if(el === 1) break;
});
</code></pre>
<p>How can I do this using the new <code>forEach</code> method in JavaScript? I've tried <code>return;</code>, <code>return false;</code> and <code>break</code>. <code>break</code> crashes and <code>return</code> does nothing but conti... | [
{
"answerId": 2641374,
"score": 2931,
"isAccepted": true,
"createdAt": "2010-04-14T22:02:14",
"ownerDisplayName": "bobince",
"ownerUserId": 18936,
"bodyText": "There's no built-in ability to break in forEach . To interrupt execution you would have to throw an exception of some sort. eg. ... | 1 |
500431 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/500431/what-is-the-scope-of-variables-in-javascript | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 500,431 | What is the scope of variables in JavaScript? | 2,223 | 585,767 | 27 | true | true | [
"javascript",
"function",
"variables",
"scope",
"var"
] | 2009-02-01T08:27:19 | 2021-06-28T11:13:30 | lYriCAlsSH | false | CC BY-SA 3.0 | 500,459 | 60,102 | 58,197 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | What is the scope of variables in javascript? Do they have the same scope inside as opposed to outside a function? Or does it even matter? Also, where are the variables stored if they are defined globally? | <p>What is the scope of variables in javascript? Do they have the same scope inside as opposed to outside a function? Or does it even matter? Also, where are the variables stored if they are defined globally?</p>
| [
{
"answerId": 500459,
"score": 2687,
"isAccepted": true,
"createdAt": "2009-02-01T08:58:50",
"ownerDisplayName": "Kenan Banks",
"ownerUserId": 43089,
"bodyText": "TLDR JavaScript has lexical (also called static) scoping and closures. This means you can tell the scope of an identifier by ... | 1 |
1353684 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/1353684/detecting-an-invalid-date-date-instance-in-javascript | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 1,353,684 | Detecting an "invalid date" Date instance in JavaScript | 2,222 | 1,665,691 | 56 | true | true | [
"javascript",
"date"
] | 2009-08-30T11:34:40 | 2025-08-27T09:46:17 | orip | false | CC BY-SA 3.0 | 1,353,711 | 37,020 | 76,144 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I'd like to tell the difference between valid and invalid date objects in JS, but couldn't figure out how: var d = new Date("foo"); console.log(d.toString()); // shows 'Invalid Date' console.log(typeof d); // shows 'object' console.log(d instanceof Date); // shows 'true' Any ideas for writing an isValidDate function? A... | <p>I'd like to tell the difference between valid and invalid date objects in JS, but couldn't figure out how:</p>
<pre><code>var d = new Date("foo");
console.log(d.toString()); // shows 'Invalid Date'
console.log(typeof d); // shows 'object'
console.log(d instanceof Date); // shows 'true'
</code></pre>
<p>Any ideas f... | null | 0 |
3102819 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/3102819/disable-same-origin-policy-in-chrome | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 3,102,819 | Disable same origin policy in Chrome | 2,218 | 3,852,788 | 39 | true | true | [
"javascript",
"ajax",
"google-chrome"
] | 2010-06-23T15:00:21 | 2026-07-07T07:56:54 | Landon Kuhn | false | CC BY-SA 4.0 | 3,177,718 | 1,785 | 79,061 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | Is there any way to disable the Same-origin policy on Google's Chrome browser? | <p>Is there any way to disable the <a href="https://en.wikipedia.org/wiki/Same_origin_policy" rel="noreferrer">Same-origin policy</a> on Google's <a href="http://en.wikipedia.org/wiki/Google_Chrome" rel="noreferrer">Chrome</a> browser?</p>
| null | 0 |
1232040 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/1232040/how-do-i-empty-an-array-in-javascript | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 1,232,040 | How do I empty an array in JavaScript? | 2,192 | 4,412,952 | 17 | true | true | [
"javascript",
"arrays"
] | 2009-08-05T09:08:39 | 2024-09-18T07:00:21 | akano1 | false | CC BY-SA 3.0 | 1,232,046 | 149,738 | 41,952 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | Is there a way to empty an array and if so possibly with .remove() ? For instance, A = [1,2,3,4]; How can I empty that? | <p>Is there a way to empty an array and if so possibly with <code>.remove()</code>?</p>
<p>For instance, </p>
<pre><code>A = [1,2,3,4];
</code></pre>
<p>How can I empty that?</p>
| [
{
"answerId": 1232046,
"score": 5714,
"isAccepted": true,
"createdAt": "2009-08-05T09:10:00",
"ownerDisplayName": "Philippe Leybaert",
"ownerUserId": 113570,
"bodyText": "Ways to clear an existing array A : Method 1 (this was my original answer to the question) A = []; This code will set... | 2 |
5062614 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/5062614/how-to-decide-when-to-use-node-js | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 5,062,614 | How to decide when to use Node.js? | 2,190 | 590,176 | 17 | true | true | [
"javascript",
"node.js",
"web-applications"
] | 2011-02-21T05:20:51 | 2026-07-06T17:30:02 | Legend | false | CC BY-SA 4.0 | 5,062,670 | 184,046 | 117,828 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I am new to this kind of stuff, but lately I've been hearing a lot about how good Node.js is. Considering how much I love working with jQuery and JavaScript in general, I can't help but wonder how to decide when to use Node.js. The web application I have in mind is something like Bitly - takes some content, archives it... | <p>I am new to this kind of stuff, but lately I've been hearing a lot about how good <a href="http://en.wikipedia.org/wiki/Node.js" rel="nofollow noreferrer">Node.js</a> is. Considering how much I love working with jQuery and JavaScript in general, I can't help but wonder how to decide when to use Node.js. The web appl... | null | 0 |
3216013 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/3216013/get-the-last-item-in-an-array | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 3,216,013 | Get the last item in an array | 2,186 | 3,671,512 | 64 | true | true | [
"javascript",
"arrays"
] | 2010-07-09T19:45:06 | 2025-07-17T06:39:28 | balexander | false | CC BY-SA 4.0 | 3,216,041 | 316,429 | 24,669 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | Here is my JavaScript code so far: var linkElement = document.getElementById("BackButton"); var loc_array = document.location.href.split('/'); var newT = document.createTextNode(unescape(capWords(loc_array[loc_array.length-2]))); linkElement.appendChild(newT); Currently it takes the second to last item in the array fro... | <p>Here is my JavaScript code so far:</p>
<pre><code>var linkElement = document.getElementById("BackButton");
var loc_array = document.location.href.split('/');
var newT = document.createTextNode(unescape(capWords(loc_array[loc_array.length-2])));
linkElement.appendChild(newT);
</code></pre>
<p>Currently it takes th... | [
{
"answerId": 3216041,
"score": 2590,
"isAccepted": true,
"createdAt": "2010-07-09T19:48:58",
"ownerDisplayName": "Aaron Butacov",
"ownerUserId": 365695,
"bodyText": "if (loc_array[loc_array.length - 1] === 'index.html') { // do something } else { // something else } In the event that yo... | 2 |
767486 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/767486/how-do-i-check-if-a-variable-is-an-array-in-javascript | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 767,486 | How do I check if a variable is an array in JavaScript? | 2,185 | 1,380,175 | 26 | true | true | [
"javascript",
"arrays",
"list",
"variables"
] | 2009-04-20T09:02:59 | 2024-07-11T04:04:35 | Andy McCluggage | false | CC BY-SA 4.0 | 26,633,883 | 3,362 | 38,978 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | How do I check if a variable is an array in JavaScript? if (variable.constructor == Array) | <p>How do I check if a variable is an array in JavaScript?</p>
<pre><code>if (variable.constructor == Array)
</code></pre>
| [
{
"answerId": 26633883,
"score": 2069,
"isAccepted": true,
"createdAt": "2014-10-29T15:07:05",
"ownerDisplayName": "jemiloii",
"ownerUserId": 630496,
"bodyText": "There are several ways of checking if an variable is an array or not. The best solution is the one you have chosen. variable.... | 1 |
572897 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/572897/how-does-javascript-prototype-work | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 572,897 | How does JavaScript .prototype work? | 2,184 | 521,676 | 26 | true | true | [
"javascript",
"dynamic-languages",
"prototype-oriented"
] | 2009-02-21T12:31:18 | 2024-05-17T05:14:24 | John Leidegren | false | CC BY-SA 4.0 | 572,996 | 58,961 | 61,382 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I'm not that into dynamic programming languages but I've written my fair share of JavaScript code. I never really got my head around this prototype-based programming, does any one know how this works? var obj = new Object(); obj.prototype.test = function() { alert('Hello?'); }; var obj2 = new obj(); obj2.test(); I reme... | <p>I'm not that into dynamic programming languages but I've written my fair share of JavaScript code. I never really got my head around this prototype-based programming, does any one know how this works?</p>
<pre><code>var obj = new Object();
obj.prototype.test = function() { alert('Hello?'); };
var obj2 = new obj();
o... | [
{
"answerId": 4778408,
"score": 1834,
"isAccepted": false,
"createdAt": "2011-01-24T03:42:35",
"ownerDisplayName": "stivlo",
"ownerUserId": 445543,
"bodyText": "In a language implementing classical inheritance like Java, C# or C++ you start by creating a class--a blueprint for your objec... | 1 |
4459379 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/4459379/preview-an-image-before-it-is-uploaded | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 4,459,379 | Preview an image before it is uploaded | 2,175 | 1,890,132 | 30 | true | true | [
"javascript",
"jquery",
"file-upload"
] | 2010-12-16T09:51:32 | 2024-08-20T12:09:16 | Simbian | false | CC BY-SA 3.0 | 4,459,419 | 518,838 | 21,953 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I want to be able to preview a file (image) before it is uploaded. The preview action should be executed all in the browser without using Ajax to upload the image. How can I do this? | <p>I want to be able to preview a file (image) before it is uploaded. The preview action should be executed all in the browser without using Ajax to upload the image.</p>
<p>How can I do this?</p>
| [
{
"answerId": 4459419,
"score": 3374,
"isAccepted": true,
"createdAt": "2010-12-16T09:55:11",
"ownerDisplayName": "Ivan Baev",
"ownerUserId": 344437,
"bodyText": "imgInp.onchange = evt => { const [file] = imgInp.files if (file) { blah.src = URL.createObjectURL(file) } } <form runat=\"ser... | 1 |
7486085 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/7486085/how-to-create-a-copy-of-a-javascript-array-instead-of-a-reference | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 7,486,085 | How to create a copy of a JavaScript array instead of a reference? | 2,165 | 1,332,765 | 40 | true | true | [
"javascript",
"arrays",
"deep-copy",
"pass-by-value"
] | 2011-09-20T13:38:08 | 2026-05-04T10:12:20 | Dan | false | CC BY-SA 4.0 | 7,486,130 | 944,555 | 21,937 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | When copying an array in JavaScript to another array: var arr1 = ['a','b','c']; var arr2 = arr1; arr2.push('d'); console.log(arr1); //= ['a','b','c','d'] I realized that arr2 refers to the same array as arr1 , rather than a new, independent array. How can I copy the array to get two independent arrays? | <p>When copying an array in JavaScript to another array:</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false" data-babel-preset-react="false" data-babel-preset-ts="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>var arr1 =... | [
{
"answerId": 7486130,
"score": 3156,
"isAccepted": true,
"createdAt": "2011-09-20T13:41:21",
"ownerDisplayName": "Saket",
"ownerUserId": 946312,
"bodyText": "Use this: let oldArray = [1, 2, 3, 4, 5]; let newArray = oldArray.slice(); console.log({newArray}); Basically, the slice() operat... | 1 |
7364150 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/7364150/search-an-array-of-javascript-objects-for-an-object-with-a-matching-value | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 7,364,150 | Search an array of JavaScript objects for an object with a matching value | 2,160 | 2,542,696 | 37 | true | true | [
"javascript",
"arrays",
"javascript-objects"
] | 2011-09-09T15:42:29 | 2024-09-02T17:18:01 | thugsb | false | CC BY-SA 4.0 | 35,398,031 | 614,566 | 23,486 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I've got an array: myArray = [{'id':'73','foo':'bar'},{'id':'45','foo':'bar'}, etc.] I'm unable to change the structure of the array. I'm being passed an id of 45 , and I want to get 'bar' for that object in the array. How do I do this in JavaScript or using jQuery? | <p>I've got an array:</p>
<pre><code>myArray = [{'id':'73','foo':'bar'},{'id':'45','foo':'bar'}, etc.]
</code></pre>
<p>I'm unable to change the structure of the array. I'm being passed an id of <code>45</code>, and I want to get <code>'bar'</code> for that object in the array. </p>
<p>How do I do this in JavaScript... | [
{
"answerId": 35398031,
"score": 2212,
"isAccepted": true,
"createdAt": "2016-02-14T21:11:10",
"ownerDisplayName": "Michał Perłakowski",
"ownerUserId": 3853934,
"bodyText": "Use the find() method: myArray.find(x => x.id === '45').foo; From MDN : The find() method returns the first value ... | 2 |
957537 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/957537/how-can-i-display-a-javascript-object | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 957,537 | How can I display a JavaScript object? | 2,151 | 2,639,962 | 40 | true | true | [
"javascript",
"serialization",
"javascript-objects"
] | 2009-06-05T19:01:59 | 2024-11-07T11:17:08 | maxjackie | false | CC BY-SA 4.0 | 957,633 | 118,061 | 23,482 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | How do I display the content of a JavaScript object in a string format like when we alert a variable? The same formatted way I want to display an object. | <p>How do I display the content of a JavaScript object in a string format like when we <code>alert</code> a variable?</p>
<p>The same formatted way I want to display an object.</p>
| [
{
"answerId": 4293047,
"score": 2500,
"isAccepted": false,
"createdAt": "2010-11-27T17:52:28",
"ownerDisplayName": "Sandeep",
"ownerUserId": 218857,
"bodyText": "Use native JSON.stringify method. Works with nested objects and all major browsers support this method. str = JSON.stringify(o... | 1 |
2496710 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/2496710/writing-to-files-in-node-js | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 2,496,710 | Writing to files in Node.js | 2,128 | 2,189,346 | 19 | true | true | [
"javascript",
"node.js",
"file",
"express",
"fs"
] | 2010-03-23T00:25:02 | 2024-12-06T15:31:07 | Gjorgji | false | CC BY-SA 4.0 | 2,497,040 | 282,329 | 23,164 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I've been trying to find a way to write to a file when using Node.js, but with no success. How can I do that? | <p>I've been trying to find a way to write to a file when using Node.js, but with no success. How can I do that?</p>
| [
{
"answerId": 2497040,
"score": 3030,
"isAccepted": true,
"createdAt": "2010-03-23T01:50:15",
"ownerDisplayName": "Brian McKenna",
"ownerUserId": 108359,
"bodyText": "There are a lot of details in the File System API . The most common way is: const fs = require('fs'); fs.writeFile(\"/tmp... | 1 |
22876978 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/22876978/loop-inside-react-jsx | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 22,876,978 | Loop inside React JSX | 2,105 | 2,212,247 | 88 | true | true | [
"javascript",
"reactjs",
"jsx"
] | 2014-04-05T05:29:28 | 2025-02-11T12:26:59 | B Robster | false | CC BY-SA 4.0 | 22,877,049 | 652,693 | 42,213 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I'm trying to do something like the following in React JSX (where ObjectRow is a separate component): <tbody> for (var i=0; i < numrows; i++) { <ObjectRow/> } </tbody> I realize and understand why this isn't valid JSX, since JSX maps to function calls. However, coming from template land and being new to JSX, I am unsur... | <p>I'm trying to do something like the following in React JSX (where ObjectRow is a separate component):</p>
<pre><code><tbody>
for (var i=0; i < numrows; i++) {
<ObjectRow/>
}
</tbody>
</code></pre>
<p>I realize and understand why this isn't valid JSX, since JSX maps to function c... | [
{
"answerId": 22877049,
"score": 1830,
"isAccepted": true,
"createdAt": "2014-04-05T05:39:46",
"ownerDisplayName": "Sophie Alpert",
"ownerUserId": 49485,
"bodyText": "Think of it like you're just calling JavaScript functions. You can't use a for loop where the arguments to a function cal... | 1 |
500504 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/500504/why-is-using-for-in-for-array-iteration-a-bad-idea | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 500,504 | Why is using "for...in" for array iteration a bad idea? | 2,102 | 1,087,399 | 28 | true | true | [
"javascript",
"arrays",
"loops",
"for-loop",
"iteration"
] | 2009-02-01T09:46:38 | 2023-05-16T13:05:57 | lYriCAlsSH | false | CC BY-SA 4.0 | 500,531 | 60,102 | 58,197 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I've been told not to use for...in with arrays in JavaScript. Why not? | <p>I've been told not to use <code>for...in</code> with arrays in JavaScript. Why not?</p>
| [
{
"answerId": 500531,
"score": 1742,
"isAccepted": true,
"createdAt": "2009-02-01T10:08:34",
"ownerDisplayName": "Kenan Banks",
"ownerUserId": 43089,
"bodyText": "The reason is that one construct: var a = []; // Create a new empty array. a[5] = 5; // Perfectly legal JavaScript that resiz... | 1 |
1144805 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/1144805/scroll-to-the-top-of-the-page-using-javascript | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 1,144,805 | Scroll to the top of the page using JavaScript? | 2,088 | 2,586,692 | 50 | true | true | [
"javascript",
"scroll"
] | 2009-07-17T17:59:09 | 2023-10-06T20:55:14 | KingNestor | false | CC BY-SA 4.0 | 1,145,012 | 64,878 | 68,490 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | How do I scroll to the top of the page using JavaScript? The scrollbar instantly jumping to the top of the page is desirable too as I'm not looking to achieve smooth scrolling. | <p>How do I scroll to the top of the page using JavaScript? The scrollbar instantly jumping to the top of the page is desirable too as I'm not looking to achieve smooth scrolling.</p>
| [
{
"answerId": 1145012,
"score": 2732,
"isAccepted": true,
"createdAt": "2009-07-17T18:42:35",
"ownerDisplayName": "SavoryBytes",
"ownerUserId": 131944,
"bodyText": "If you don't need the change to animate then you don't need to use any special plugins - I'd just use the native JavaScript... | 2 |
27732209 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/27732209/turning-off-an-eslint-rule-for-a-specific-line | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 27,732,209 | Turning off an ESLint rule for a specific line | 2,071 | 1,865,480 | 15 | true | true | [
"javascript",
"jshint",
"eslint"
] | 2015-01-01T15:47:47 | 2026-03-04T03:52:43 | runtimeZero | false | CC BY-SA 4.0 | 29,592,334 | 2,117,019 | 28,476 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | In order to turn off a linting rule for a particular line in JSHint, we use the following rule: /* jshint ignore:start*/ $scope.someVar = ConstructorFunction(); /* jshint ignore:end */ Is there an equivalent of the above for ESLint? | <p>In order to turn off a linting rule for a particular line in JSHint, we use the following rule:</p>
<pre><code>/* jshint ignore:start*/
$scope.someVar = ConstructorFunction();
/* jshint ignore:end */
</code></pre>
<p>Is there an equivalent of the above for ESLint?</p>
| [
{
"answerId": 29592334,
"score": 3240,
"isAccepted": true,
"createdAt": "2015-04-12T17:27:38",
"ownerDisplayName": "goofballLogic",
"ownerUserId": 275501,
"bodyText": "To disable the next line: // eslint-disable-next-line no-use-before-define var thing = new Thing(); Or use the single li... | 1 |
2450954 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 2,450,954 | How to randomize (shuffle) a JavaScript array? | 2,068 | 1,793,713 | 58 | true | true | [
"javascript",
"arrays",
"random",
"shuffle"
] | 2010-03-15T22:37:11 | 2025-03-21T07:11:59 | Ali | false | CC BY-SA 4.0 | 2,450,976 | 49,153 | 268,312 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I have an array like this: var arr1 = ["a", "b", "c", "d"]; How can I randomize / shuffle it? | <p>I have an array like this:</p>
<pre><code>var arr1 = ["a", "b", "c", "d"];
</code></pre>
<p>How can I randomize / shuffle it?</p>
| [
{
"answerId": 2450976,
"score": 2628,
"isAccepted": true,
"createdAt": "2010-03-15T22:41:10",
"ownerDisplayName": "ChristopheD",
"ownerUserId": 81179,
"bodyText": "The de-facto unbiased shuffle algorithm is the Fisher–Yates (aka Knuth) Shuffle . You can see a great visualization here . f... | 1 |
175739 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/175739/how-can-i-check-if-a-string-is-a-valid-number | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 175,739 | How can I check if a string is a valid number? | 2,051 | 1,979,976 | 56 | true | true | [
"javascript",
"validation",
"numeric"
] | 2008-10-06T19:12:52 | 2026-01-15T18:59:05 | Electrons_Ahoy | false | CC BY-SA 4.0 | 175,787 | 19,074 | 39,141 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I'm hoping there's something in the same conceptual space as the old VB6 IsNumeric() function? | <p>I'm hoping there's something in the same conceptual space as the old VB6 <code>IsNumeric()</code> function?</p>
| [
{
"answerId": 175787,
"score": 3317,
"isAccepted": true,
"createdAt": "2008-10-06T19:24:20",
"ownerDisplayName": "Dan",
"ownerUserId": 17121,
"bodyText": "2nd October 2020: note that many bare-bones approaches are fraught with subtle bugs (eg. whitespace, implicit partial parsing, radix,... | 1 |
9682092 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/9682092/how-does-data-binding-work-in-angularjs | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 9,682,092 | How does data binding work in AngularJS? | 2,050 | 366,118 | 14 | true | true | [
"javascript",
"angularjs",
"data-binding"
] | 2012-03-13T10:16:37 | 2018-11-05T12:56:41 | Pashec | false | CC BY-SA 3.0 | 9,693,933 | 168,367 | 23,279 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | How does data binding work in the AngularJS framework? I haven't found technical details on their site . It's more or less clear how it works when data is propagated from view to model. But how does AngularJS track changes of model properties without setters and getters? I found that there are JavaScript watchers that ... | <p>How does data binding work in the <code>AngularJS</code> framework?</p>
<p>I haven't found technical details on <a href="http://angularjs.org" rel="noreferrer">their site</a>. It's more or less clear how it works when data is propagated from view to model. But how does AngularJS track changes of model properties wi... | [
{
"answerId": 9693933,
"score": 2763,
"isAccepted": true,
"createdAt": "2012-03-13T23:47:35",
"ownerDisplayName": "Misko Hevery",
"ownerUserId": 192810,
"bodyText": "AngularJS remembers the value and compares it to a previous value. This is basic dirty-checking. If there is a change in v... | 1 |
126100 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/126100/how-to-efficiently-count-the-number-of-keys-properties-of-an-object-in-javascrip | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 126,100 | How to efficiently count the number of keys/properties of an object in JavaScript | 2,046 | 1,092,306 | 19 | true | true | [
"javascript",
"performance",
"properties",
"count",
"key"
] | 2008-09-24T08:56:21 | 2025-01-16T02:30:15 | mjs | false | CC BY-SA 4.0 | 4,889,658 | 11,543 | 65,593 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | What’s the fastest way to count the number of keys/properties of an object? Is it possible to do this without iterating over the object, i.e., without doing: var count = 0; for (k in myobj) if (myobj.hasOwnProperty(k)) ++count; (Firefox did provide a magic __count__ property, but this was removed somewhere around versi... | <p>What’s the fastest way to count the number of keys/properties of an object? Is it possible to do this without iterating over the object, i.e., without doing:</p>
<pre><code>var count = 0;
for (k in myobj) if (myobj.hasOwnProperty(k)) ++count;
</code></pre>
<p>(Firefox did provide a magic <code>__count__</code> prope... | [
{
"answerId": 4889658,
"score": 3212,
"isAccepted": true,
"createdAt": "2011-02-03T17:47:20",
"ownerDisplayName": "Avi Flax",
"ownerUserId": 7012,
"bodyText": "To do this in any ES5 -compatible environment , such as Node.js , Chrome, Internet Explorer 9+ , Firefox 4+, or Safari 5+: Objec... | 1 |
1584370 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/1584370/how-to-merge-two-arrays-in-javascript-and-de-duplicate-items | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 1,584,370 | How to merge two arrays in JavaScript and de-duplicate items | 2,032 | 2,257,530 | 93 | true | true | [
"javascript",
"arrays",
"merge"
] | 2009-10-18T08:34:57 | 2025-05-20T15:58:46 | Vijjendra | false | CC BY-SA 3.0 | 1,584,377 | 165,873 | 25,301 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I have two JavaScript arrays: var array1 = ["Vijendra","Singh"]; var array2 = ["Singh", "Shakya"]; I want the output to be: var array3 = ["Vijendra","Singh","Shakya"]; The output array should have repeated words removed. How do I merge two arrays in JavaScript so that I get only the unique items from each array in the ... | <p>I have two JavaScript arrays:</p>
<pre><code>var array1 = ["Vijendra","Singh"];
var array2 = ["Singh", "Shakya"];
</code></pre>
<p>I want the output to be:</p>
<pre><code>var array3 = ["Vijendra","Singh","Shakya"];
</code></pre>
<p>The output array should have repeated words removed.</p>
<p>How do I merge two a... | [
{
"answerId": 1584377,
"score": 2352,
"isAccepted": true,
"createdAt": "2009-10-18T08:42:43",
"ownerDisplayName": "LiraNuna",
"ownerUserId": 41983,
"bodyText": "To just merge the arrays (without removing duplicates) ES5 version use Array.concat : var array1 = [\"Vijendra\", \"Singh\"]; v... | 1 |
455338 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/455338/how-do-i-check-if-an-object-has-a-key-in-javascript | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 455,338 | How do I check if an object has a key in JavaScript? | 2,032 | 2,339,104 | 2 | true | true | [
"javascript",
"object"
] | 2009-01-18T15:42:58 | 2020-01-09T10:52:24 | kevin | true | null | 455,366 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | Which is the right thing to do? if (myObj['key'] == undefined) or if (myObj['key'] == null) or if (myObj['key']) | <p>Which is the right thing to do?</p>
<pre><code>if (myObj['key'] == undefined)
</code></pre>
<p>or</p>
<pre><code>if (myObj['key'] == null)
</code></pre>
<p>or</p>
<pre><code>if (myObj['key'])
</code></pre>
| [
{
"answerId": 455366,
"score": 3511,
"isAccepted": true,
"createdAt": "2009-01-18T16:03:00",
"ownerDisplayName": "ForYourOwnGood",
"ownerUserId": 48728,
"bodyText": "Try the JavaScript in operator . if ('key' in myObj) And the inverse. if (!('key' in myObj)) Be careful! The in operator m... | 1 |
446594 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/446594/abort-ajax-requests-using-jquery | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 446,594 | Abort Ajax requests using jQuery | 2,007 | 732,598 | 18 | true | true | [
"javascript",
"jquery",
"ajax"
] | 2009-01-15T12:45:18 | 2024-04-09T01:03:07 | lukewm | false | CC BY-SA 4.0 | 446,626 | 47,831 | 21,763 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | Is it possible that using jQuery, I cancel/abort an Ajax request that I have not yet received the response from? | <p>Is it possible that using jQuery, I <strong>cancel/abort an Ajax request</strong> that I have not yet received the response from?</p>
| [
{
"answerId": 446626,
"score": 1867,
"isAccepted": true,
"createdAt": "2009-01-15T12:56:49",
"ownerDisplayName": "meouw",
"ownerUserId": 12161,
"bodyText": "Most of the jQuery Ajax methods return an XMLHttpRequest (or the equivalent) object, so you can just use abort() . See the document... | 1 |
1168807 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/1168807/how-can-i-add-a-key-value-pair-to-a-javascript-object | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 1,168,807 | How can I add a key/value pair to a JavaScript object? | 1,999 | 4,248,208 | 17 | true | true | [
"javascript",
"object-literal"
] | 2009-07-22T23:21:51 | 2025-01-01T13:58:53 | James Skidmore | false | CC BY-SA 4.0 | 1,168,814 | 95,267 | 50,468 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | Here is my object literal: var obj = {key1: value1, key2: value2}; How can I add field key3 with value3 to the object? | <p>Here is my object literal:</p>
<pre><code>var obj = {key1: value1, key2: value2};
</code></pre>
<p>How can I add field <code>key3</code> with <code>value3</code> to the object?</p>
| [
{
"answerId": 1168814,
"score": 3048,
"isAccepted": true,
"createdAt": "2009-07-22T23:25:19",
"ownerDisplayName": "Ionuț G. Stan",
"ownerUserId": 58808,
"bodyText": "There are two ways to add new properties to an object: var obj = { key1: value1, key2: value2 }; Using dot notation: obj.k... | 1 |
494035 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/494035/how-do-you-use-a-variable-in-a-regular-expression | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 494,035 | How do you use a variable in a regular expression? | 1,982 | 1,363,277 | 29 | true | true | [
"javascript",
"regex"
] | 2009-01-30T00:11:05 | 2025-09-25T12:46:29 | JC Grubbs | false | CC BY-SA 4.0 | 494,046 | 4,541 | 40,591 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I would like to create a String.replaceAll() method in JavaScript and think using a regex would be the most terse way to do it. However, I can't figure out how to pass a variable into a regex. I can do this already which will replace all the instances of "B" with "A" . "ABABAB".replace(/B/g, "A"); But I want to do some... | <p>I would like to create a <code>String.replaceAll()</code> method in JavaScript and think using a regex would be the most terse way to do it. However, I can't figure out how to pass a variable into a regex. I can do this already which will replace all the instances of <code>"B"</code> with <code>"A&q... | [
{
"answerId": 494046,
"score": 2446,
"isAccepted": true,
"createdAt": "2009-01-30T00:15:40",
"ownerDisplayName": "Eric Wendelin",
"ownerUserId": 25066,
"bodyText": "Instead of using the /\\sREGEX\\s/g syntax, you can construct a new RegExp object: // variable == 'REGEX' let re = new RegE... | 1 |
19590865 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/19590865/from-an-array-of-objects-extract-value-of-a-property-as-array | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 19,590,865 | From an array of objects, extract value of a property as array | 1,975 | 2,036,475 | 26 | true | true | [
"javascript",
"javascript-objects"
] | 2013-10-25T13:13:03 | 2025-02-15T16:44:54 | hyde | false | CC BY-SA 4.0 | 46,694,321 | 1,717,300 | 63,303 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I have JavaScript object array with the following structure: objArray = [ { foo: 1, bar: 2}, { foo: 3, bar: 4}, { foo: 5, bar: 6} ]; I want to extract a field from each object, and get an array containing the values, for example field foo would give array [ 1, 3, 5 ] . I can do this with this trivial approach: function... | <p>I have JavaScript object array with the following structure:</p>
<pre><code>objArray = [ { foo: 1, bar: 2}, { foo: 3, bar: 4}, { foo: 5, bar: 6} ];
</code></pre>
<p>I want to extract a field from each object, and get an array containing the values, for example field <code>foo</code> would give array <code>[ 1, 3, ... | [
{
"answerId": 46694321,
"score": 2663,
"isAccepted": true,
"createdAt": "2017-10-11T17:33:48",
"ownerDisplayName": "Jalasem",
"ownerUserId": 3848424,
"bodyText": "Here is a shorter way of achieving it: let result = objArray.map(a => a.foo); OR let result = objArray.map(({ foo }) => foo) ... | 1 |
57803 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/57803/how-to-convert-decimal-to-hexadecimal-in-javascript | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 57,803 | How to convert decimal to hexadecimal in JavaScript | 1,973 | 1,548,913 | 31 | true | true | [
"javascript",
"hex",
"number-formatting",
"radix"
] | 2008-09-11T22:26:58 | 2024-10-08T08:44:52 | Luke Smith | false | CC BY-SA 4.0 | 57,805 | 5,556 | 24,394 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | How do you convert decimal values to their hexadecimal equivalent in JavaScript? | <p>How do you convert decimal values to their hexadecimal equivalent in JavaScript?</p>
| [
{
"answerId": 57805,
"score": 3275,
"isAccepted": true,
"createdAt": "2008-09-11T22:28:34",
"ownerDisplayName": "Prestaul",
"ownerUserId": 5628,
"bodyText": "Convert a number to a hexadecimal string with: hexString = yourNumber.toString(16); And reverse the process with: yourNumber = par... | 1 |
3514784 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/3514784/how-to-detect-a-mobile-device-using-jquery | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 3,514,784 | How to detect a mobile device using jQuery | 1,965 | 1,977,006 | 65 | true | true | [
"javascript",
"jquery",
"mobile",
"browser-detection"
] | 2010-08-18T17:22:22 | 2024-01-18T23:00:54 | superUntitled | false | CC BY-SA 4.0 | 3,540,295 | 54,259 | 22,622 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | Is there a way to detect whether or not a user is using a mobile device in jQuery? Something similar to the CSS @media attribute? I would like to run a different script if the browser is on a handheld device. The jQuery $.browser function is not what I am looking for. | <p>Is there a way to detect whether or not a user is using a mobile device in jQuery? Something similar to the CSS <code>@media</code> attribute? I would like to run a different script if the browser is on a handheld device.</p>
<p>The jQuery <code>$.browser</code> function is not what I am looking for.</p>
| [
{
"answerId": 3540295,
"score": 2310,
"isAccepted": true,
"createdAt": "2010-08-22T05:26:26",
"ownerDisplayName": "sweets-BlingBling",
"ownerUserId": 427242,
"bodyText": "Editor's note: user agent detection is not a recommended technique for modern web apps. See the comments below this a... | 1 |
436411 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/436411/where-should-i-put-script-tags-in-html-markup | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 436,411 | Where should I put <script> tags in HTML markup? | 1,960 | 912,028 | 22 | true | true | [
"javascript",
"html"
] | 2009-01-12T18:15:54 | 2024-10-12T13:03:20 | mipadi | false | CC BY-SA 4.0 | 24,070,373 | 28,804 | 414,647 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | When embedding JavaScript in an HTML document, where is the proper place to put the <script> tags and included JavaScript? I seem to recall that you are not supposed to place these in the <head> section, but placing at the beginning of the <body> section is bad, too, since the JavaScript will have to be parsed before t... | <p>When embedding JavaScript in an HTML document, where is the proper place to put the <code><script></code> tags and included JavaScript? I seem to recall that you are not supposed to place these in the <code><head></code> section, but placing at the beginning of the <code><body></code> section is ba... | [
{
"answerId": 24070373,
"score": 2472,
"isAccepted": true,
"createdAt": "2014-06-05T21:20:51",
"ownerDisplayName": "Bart",
"ownerUserId": 454531,
"bodyText": "Here's what happens when a browser loads a website with a <script> tag on it: Fetch the HTML page (e.g. index.html ) Begin parsin... | 1 |
12694530 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/12694530/what-is-typescript-and-why-should-i-use-it-instead-of-javascript | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 12,694,530 | What is TypeScript and why should I use it instead of JavaScript? | 1,939 | 697,583 | 5 | true | true | [
"javascript",
"typescript"
] | 2012-10-02T16:37:58 | 2026-07-14T10:29:05 | Mohammed Thabet | false | CC BY-SA 4.0 | 12,694,578 | 353,953 | 21,709 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | What is the TypeScript language? What can it do that JavaScript or available libraries cannot do, that would give me reason to consider it? | <p>What is the TypeScript language? What can it do that JavaScript or available libraries cannot do, that would give me reason to consider it?</p>
| [
{
"answerId": 12694578,
"score": 1441,
"isAccepted": true,
"createdAt": "2012-10-02T16:41:28",
"ownerDisplayName": "Paul Dixon",
"ownerUserId": 6521,
"bodyText": "I originally wrote this answer when TypeScript was still hot-off-the-presses. Five years later, this is an OK overview, but l... | 1 |
1279957 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/1279957/how-to-move-an-element-into-another-element | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 1,279,957 | How to move an element into another element | 1,938 | 1,465,153 | 16 | true | true | [
"javascript",
"jquery",
"html"
] | 2009-08-14T20:14:45 | 2024-10-08T08:21:47 | Mark Richman | false | CC BY-SA 4.0 | 1,279,963 | 134,484 | 29,830 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I would like to move one DIV element inside another. For example, I want to move this (including all children): <div id="source"> ... </div> into this: <div id="destination"> ... </div> so that I have this: <div id="destination"> <div id="source"> ... </div> </div> | <p>I would like to move one DIV element inside another. For example, I want to move this (including all children):</p>
<pre class="lang-html prettyprint-override"><code><div id="source">
...
</div>
</code></pre>
<p>into this:</p>
<pre class="lang-html prettyprint-override"><code><div id="... | [
{
"answerId": 1279963,
"score": 1955,
"isAccepted": true,
"createdAt": "2009-08-14T20:16:45",
"ownerDisplayName": "Andrew Hare",
"ownerUserId": 34211,
"bodyText": "You may want to use the appendTo function (which adds to the end of the element): $(\"#source\").appendTo(\"#destination\");... | 1 |
1646698 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/1646698/what-is-the-new-keyword-in-javascript | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 1,646,698 | What is the 'new' keyword in JavaScript? | 1,931 | 386,461 | 18 | true | true | [
"javascript",
"new-operator"
] | 2009-10-29T21:32:45 | 2024-07-23T22:14:49 | Alon Gubkin | false | CC BY-SA 3.0 | 3,658,673 | 140,937 | 57,251 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | The new keyword in JavaScript can be quite confusing when it is first encountered, as people tend to think that JavaScript is not an object-oriented programming language. What is it? What problems does it solve? When is it appropriate and when not? | <p>The <code>new</code> keyword in JavaScript can be quite confusing when it is first encountered, as people tend to think that JavaScript is not an object-oriented programming language.</p>
<ul>
<li>What is it?</li>
<li>What problems does it solve?</li>
<li>When is it appropriate and when not?</li>
</ul>
| [
{
"answerId": 3658673,
"score": 2304,
"isAccepted": true,
"createdAt": "2010-09-07T12:30:58",
"ownerDisplayName": "Daniel Howard",
"ownerUserId": 441426,
"bodyText": "It does 5 things: It creates a new object. The type of this object is simply object . It sets this new object's internal,... | 1 |
20279484 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/20279484/how-to-access-the-correct-this-inside-a-callback | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 20,279,484 | How to access the correct `this` inside a callback | 1,924 | 659,142 | 16 | true | true | [
"javascript",
"callback",
"this"
] | 2013-11-29T06:13:11 | 2025-10-22T20:14:45 | Felix Kling | false | CC BY-SA 4.0 | 20,279,485 | 218,196 | 821,265 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I have a constructor function which registers an event handler: function MyConstructor(data, transport) { this.data = data; transport.on('data', function () { alert(this.data); }); } // Mock transport object var transport = { on: function(event, callback) { setTimeout(callback, 1000); } }; // called as var obj = new My... | <p>I have a constructor function which registers an event handler:</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>function MyConstructor(data, transport) {
this.data = ... | [
{
"answerId": 20279485,
"score": 2315,
"isAccepted": true,
"createdAt": "2013-11-29T06:13:11",
"ownerDisplayName": "Felix Kling",
"ownerUserId": 218196,
"bodyText": "What you should know about this this (aka \"the context\") is a special keyword inside each function and its value only de... | 1 |
9899372 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/9899372/vanilla-javascript-equivalent-of-jquerys-ready-how-to-call-a-function-whe | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 9,899,372 | Vanilla JavaScript equivalent of jQuery's $.ready() - how to call a function when the page/DOM is ready for it | 1,921 | 2,374,049 | 10 | true | true | [
"javascript",
"jquery",
"html"
] | 2012-03-27T23:57:21 | 2022-06-29T20:23:23 | chris | true | null | 9,899,701 | 768,392 | 37,065 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | With jQuery, we all know the wonderful .ready() function: $('document').ready(function(){}); However, let's say I want to run a function that is written in standard JavaScript with no library backing it, and that I want to launch a function as soon as the page is ready to handle it. What's the proper way to approach th... | <p>With jQuery, we all know the wonderful <code>.ready()</code> function:</p>
<pre><code>$('document').ready(function(){});
</code></pre>
<p>However, let's say I want to run a function that is written in standard JavaScript with no library backing it, and that I want to launch a function as soon as the page is ready ... | [
{
"answerId": 9899701,
"score": 2678,
"isAccepted": true,
"createdAt": "2012-03-28T00:46:22",
"ownerDisplayName": "jfriend00",
"ownerUserId": 816620,
"bodyText": "The simplest thing to do in the absence of a framework that does all the cross-browser compatibility for you is to just put a... | 1 |
135448 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/135448/how-do-i-check-if-an-object-has-a-specific-property-in-javascript | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 135,448 | How do I check if an object has a specific property in JavaScript? | 1,910 | 1,505,995 | 33 | true | true | [
"javascript"
] | 2008-09-25T19:27:06 | 2024-08-18T04:44:04 | sheats | false | CC BY-SA 4.0 | 136,411 | 4,915 | 35,022 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | How do I check if an object has a specific property in JavaScript? Consider: x = {'key': 1}; if ( x.hasOwnProperty('key') ) { //Do this } Is there another way to do it? | <p>How do I check if an object has a specific property in JavaScript?</p>
<p>Consider:</p>
<pre><code>x = {'key': 1};
if ( x.hasOwnProperty('key') ) {
//Do this
}
</code></pre>
<p>Is there another way to do it?</p>
| [
{
"answerId": 136411,
"score": 1791,
"isAccepted": true,
"createdAt": "2008-09-25T21:52:02",
"ownerDisplayName": "John Resig",
"ownerUserId": 6524,
"bodyText": "2022 UPDATE Object.hasOwn() Object.hasOwn() is recommended over Object.hasOwnProperty() because it works for objects created us... | 1 |
18641899 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/18641899/what-is-the-difference-between-bower-and-npm | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 18,641,899 | What is the difference between Bower and npm? | 1,909 | 339,938 | 9 | true | true | [
"javascript",
"npm",
"bower",
"dependency-management"
] | 2013-09-05T16:53:19 | 2025-01-12T16:15:34 | Nafiul Islam | false | CC BY-SA 4.0 | 18,652,918 | 1,624,921 | 82,976 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | What is the fundamental difference between bower and npm ? Just want something plain and simple. I've seen some of my colleagues use bower and npm interchangeably in their projects. | <p>What is the fundamental difference between <code>bower</code> and <code>npm</code>? Just want something plain and simple. I've seen some of my colleagues use <code>bower</code> and <code>npm</code> interchangeably in their projects.</p>
| [
{
"answerId": 18652918,
"score": 1987,
"isAccepted": true,
"createdAt": "2013-09-06T08:09:28",
"ownerDisplayName": "Sindre Sorhus",
"ownerUserId": 64949,
"bodyText": "All package managers have many downsides. You just have to pick which you can live with. History npm started out managing... | 1 |
3455405 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/3455405/how-do-i-remove-a-key-from-a-javascript-object | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 3,455,405 | How do I remove a key from a JavaScript object? | 1,905 | 2,130,542 | 3 | true | true | [
"javascript"
] | 2010-08-11T04:59:03 | 2022-08-05T15:14:45 | Martin Ongtangco | true | null | 3,455,416 | 162,381 | 23,625 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | Let's say we have an object with this format: var thisIsObject= { 'Cow' : 'Moo', 'Cat' : 'Meow', 'Dog' : 'Bark' }; I wanted to do a function that removes by key: removeFromObjectByKey('Cow'); | <p>Let's say we have an object with this format:</p>
<pre><code>var thisIsObject= {
'Cow' : 'Moo',
'Cat' : 'Meow',
'Dog' : 'Bark'
};
</code></pre>
<p>I wanted to do a function that removes by key:</p>
<pre><code>removeFromObjectByKey('Cow');
</code></pre>
| [
{
"answerId": 3455416,
"score": 3224,
"isAccepted": true,
"createdAt": "2010-08-11T05:01:45",
"ownerDisplayName": "jessegavin",
"ownerUserId": 5651,
"bodyText": "The delete operator allows you to remove a property from an object. The following examples all do the same thing. // Example 1... | 1 |
7202157 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/7202157/why-does-return-the-string-10 | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 7,202,157 | Why does ++[[]][+[]]+[+[]] return the string "10"? | 1,896 | 238,255 | 10 | true | true | [
"javascript",
"syntax",
"jsfuck"
] | 2011-08-26T08:46:14 | 2024-01-29T15:25:02 | JohnJohnGa | false | CC BY-SA 4.0 | 7,202,287 | 324,853 | 15,715 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | This is valid and returns the string "10" in JavaScript ( more examples here ): console.log(++[[]][+[]]+[+[]]) Why? What is happening here? | <p>This is valid and returns the string <code>"10"</code> in JavaScript (<a href="http://sla.ckers.org/forum/read.php?24,33349,33405" rel="noreferrer">more examples here</a>):</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="s... | [
{
"answerId": 7202287,
"score": 2282,
"isAccepted": true,
"createdAt": "2011-08-26T08:56:54",
"ownerDisplayName": "pimvdb",
"ownerUserId": 514749,
"bodyText": "If we split it up, the mess is equal to: ++[[]][+[]] + [+[]] In JavaScript, it is true that +[] === 0 . + converts something int... | 1 |
14810506 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/14810506/map-function-for-objects-instead-of-arrays | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 14,810,506 | 'map' function for objects (instead of arrays) | 1,876 | 2,995,108 | 40 | true | true | [
"javascript",
"node.js",
"functional-programming",
"map-function"
] | 2013-02-11T10:41:12 | 2025-08-05T18:36:18 | Randomblue | false | CC BY-SA 4.0 | 14,810,722 | 707,381 | 117,223 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I have an object: myObject = { 'a': 1, 'b': 2, 'c': 3 } I am looking for a native method, similar to Array.prototype.map that would be used as follows: newObject = myObject.map(function (value, label) { return value * value; }); // newObject is now { 'a': 1, 'b': 4, 'c': 9 } Does JavaScript have such a map function for... | <p>I have an object:</p>
<pre><code>myObject = { 'a': 1, 'b': 2, 'c': 3 }
</code></pre>
<p>I am looking for a native method, similar to <code>Array.prototype.map</code> that would be used as follows:</p>
<pre><code>newObject = myObject.map(function (value, label) {
return value * value;
});
// newObject is now ... | [
{
"answerId": 14810722,
"score": 2605,
"isAccepted": true,
"createdAt": "2013-02-11T10:52:37",
"ownerDisplayName": "Amberlamps",
"ownerUserId": 1191261,
"bodyText": "There is no native map to the Object object, but how about this: var myObject = { 'a': 1, 'b': 2, 'c': 3 }; Object.keys(my... | 1 |
921789 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/921789/how-to-loop-through-a-plain-javascript-object-with-the-objects-as-members | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 921,789 | How to loop through a plain JavaScript object with the objects as members | 1,840 | 2,135,521 | 30 | true | true | [
"javascript",
"loops"
] | 2009-05-28T16:18:14 | 2023-12-15T03:26:59 | edt | false | CC BY-SA 4.0 | 921,808 | 32,242 | 22,490 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | How can I loop through all members in a JavaScript object, including values that are objects? For example, how could I loop through this (accessing the "your_name" and "your_message" for each)? var validation_messages = { "key_1": { "your_name": "jimmy", "your_msg": "hello world" }, "key_2": { "your_name": "billy", "yo... | <p>How can I loop through all members in a JavaScript object, including values that are objects?</p>
<p>For example, how could I loop through this (accessing the "your_name" and "your_message" for each)?</p>
<pre><code>var validation_messages = {
"key_1": {
"your_name"... | [
{
"answerId": 921808,
"score": 2267,
"isAccepted": true,
"createdAt": "2009-05-28T16:20:58",
"ownerDisplayName": "AgileJon",
"ownerUserId": 1423,
"bodyText": "for (var key in validation_messages) { // skip loop if the property is from prototype if (!validation_messages.hasOwnProperty(key... | 1 |
646628 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/646628/how-to-check-if-a-string-startswith-another-string | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 646,628 | How to check if a string "StartsWith" another string? | 1,826 | 1,076,974 | 19 | true | true | [
"javascript",
"string",
"startswith"
] | 2009-03-14T20:12:51 | 2023-12-12T19:03:35 | sol | false | CC BY-SA 4.0 | 646,643 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | How would I write the equivalent of C#'s String.StartsWith in JavaScript? var haystack = 'hello world'; var needle = 'he'; haystack.startsWith(needle) == true Note: This is an old question, and as pointed out in the comments ECMAScript 2015 (ES6) introduced the .startsWith method. However, at the time of writing this u... | <p>How would I write the equivalent of C#'s <a href="http://msdn.microsoft.com/en-us/library/baketfxw.aspx" rel="noreferrer"><code>String.StartsWith</code></a> in JavaScript?</p>
<pre><code>var haystack = 'hello world';
var needle = 'he';
haystack.startsWith(needle) == true
</code></pre>
<p>Note: This is an old ques... | [
{
"answerId": 646643,
"score": 1869,
"isAccepted": true,
"createdAt": "2009-03-14T20:19:13",
"ownerDisplayName": "Christian C. Salvadó",
"ownerUserId": 5445,
"bodyText": "You can use ECMAScript 6's String.prototype.startsWith() method. It's supported in all major browsers . However, if y... | 1 |
313893 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/313893/how-to-measure-time-taken-by-a-function-to-execute | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 313,893 | How to measure time taken by a function to execute | 1,820 | 1,240,082 | 30 | true | true | [
"javascript",
"profiling"
] | 2008-11-24T11:09:14 | 2025-01-22T06:32:34 | Julius A | false | CC BY-SA 4.0 | 1,975,103 | 13,370 | 40,082 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I need to get execution time in milliseconds. Note : I originally asked this question back in 2008. The accepted answer then was to use new Date().getTime() However, we can all agree now that using the standard performance.now() API is more appropriate. I am therefore changing the accepted answer to this one. | <p>I need to get execution time in milliseconds.</p>
<p><strong>Note</strong>: I originally asked this question back in 2008. The accepted answer then was to use <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTime" rel="noreferrer"><code>new Date().getTime()</code></a>... | [
{
"answerId": 1975103,
"score": 2818,
"isAccepted": true,
"createdAt": "2009-12-29T15:05:42",
"ownerDisplayName": "vsync",
"ownerUserId": 104380,
"bodyText": "Using performance.now() : const startTime = performance.now() doSomething() // <---- measured code goes between startTime and end... | 1 |
1291942 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/1291942/what-does-javascriptvoid0-mean | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 1,291,942 | What does "javascript:void(0)" mean? | 1,810 | 2,883,608 | 14 | true | true | [
"javascript",
"void"
] | 2009-08-18T05:20:13 | 2024-07-28T13:57:20 | omg | false | CC BY-SA 4.0 | 1,291,950 | 104,015 | 141,112 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | <a href="javascript:void(0)" id="loginlink">login</a> I've seen such href s many times, but I don't know what exactly that means. | <pre class="lang-html prettyprint-override"><code><a href="javascript:void(0)" id="loginlink">login</a>
</code></pre>
<p>I've seen such <code>href</code>s many times, but I don't know what exactly that means.</p>
| null | 0 |
109086 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/109086/stop-setinterval-call-in-javascript | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 109,086 | Stop setInterval call in JavaScript | 1,802 | 1,522,385 | 9 | true | true | [
"javascript",
"dom-events",
"setinterval"
] | 2008-09-20T19:29:55 | 2023-05-13T13:21:56 | cnu | false | CC BY-SA 4.0 | 109,091 | 1,448 | 37,385 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I am using setInterval(fname, 10000); to call a function every 10 seconds in JavaScript. Is it possible to stop calling it on some event? I want the user to be able to stop the repeated refresh of data. | <p>I am using <code>setInterval(fname, 10000);</code> to call a function every 10 seconds in JavaScript. Is it possible to stop calling it on some event? </p>
<p>I want the user to be able to stop the repeated refresh of data.</p>
| [
{
"answerId": 109091,
"score": 2774,
"isAccepted": true,
"createdAt": "2008-09-20T19:30:59",
"ownerDisplayName": "John Millikin",
"ownerUserId": 3560,
"bodyText": "setInterval() returns an interval ID, which you can pass to clearInterval() : var refreshIntervalId = setInterval(fname, 100... | 1 |
11177954 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/11177954/how-do-i-completely-uninstall-node-js-and-reinstall-from-beginning-mac-os-x | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 11,177,954 | How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X) | 1,798 | 3,103,063 | 35 | true | true | [
"javascript",
"node.js",
"npm"
] | 2012-06-24T13:40:56 | 2026-02-06T09:31:54 | Dominic Tancredi | false | CC BY-SA 4.0 | 11,178,106 | 1,247,659 | 42,430 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | My version of node is always v0.6.1-pre even after I install brew node and NVM install v0.6.19. My node version is: node -v v0.6.1-pre NVM says this (after I install a version of node for the first time in one bash terminal): nvm ls v0.6.19 current: v0.6.19 But when I restart bash, this is what I see: nvm ls v0.6.19 cu... |
<p>My version of node is always v0.6.1-pre even after I install brew node and NVM install v0.6.19.</p>
<p>My node version is:</p>
<pre class="lang-none prettyprint-override"><code>node -v
v0.6.1-pre
</code></pre>
<p>NVM says this (after I install a version of node for the first time in one bash terminal):</p>
<pr... | [
{
"answerId": 11178106,
"score": 2031,
"isAccepted": true,
"createdAt": "2012-06-24T14:04:58",
"ownerDisplayName": "Dominic Tancredi",
"ownerUserId": 1247659,
"bodyText": "Apparently, there was a /Users/myusername/local folder that contained a include with node and lib with node and node... | 1 |
21692646 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/21692646/how-does-facebook-disable-the-browsers-integrated-developer-tools | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 21,692,646 | How does Facebook disable the browser's integrated Developer Tools? | 1,791 | 315,455 | 14 | true | true | [
"javascript",
"facebook",
"google-chrome-devtools"
] | 2014-02-11T03:42:08 | 2024-06-27T22:07:54 | Derek 朕會功夫 | false | CC BY-SA 4.0 | 21,693,931 | 283,863 | 94,895 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | So apparently because of the recent scams, the developer tools are exploited by people to post spam and even used to "hack" accounts. Facebook has blocked the developer tools, and I can't even use the console. How did they do that?? One Stack Overflow post claimed it is impossible , but Facebook has proven them wrong. ... | <p>So apparently because of the recent scams, the developer tools are exploited by people to post spam and even used to "hack" accounts. Facebook has blocked the developer tools, and I can't even use the console.</p>
<p><img src="https://i.sstatic.net/Wiatp.png" alt="Enter image description here" /></p>
<p>Ho... | [
{
"answerId": 21693931,
"score": 2540,
"isAccepted": true,
"createdAt": "2014-02-11T05:33:16",
"ownerDisplayName": "Alf",
"ownerUserId": 630946,
"bodyText": "I'm a security engineer at Facebook and this is my fault. We're testing this for some users to see if it can slow down some attack... | 1 |
1184624 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/1184624/convert-form-data-to-javascript-object-with-jquery | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 1,184,624 | Convert form data to JavaScript object with jQuery | 1,771 | 1,112,708 | 58 | true | true | [
"javascript",
"jquery",
"json",
"serialization"
] | 2009-07-26T13:39:54 | 2025-02-26T20:13:04 | Yisroel | false | CC BY-SA 4.0 | 1,186,309 | 35,091 | 8,174 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | How do I convert all elements of my form to a JavaScript object? I'd like to have some way of automatically building a JavaScript object from my form, without having to loop over each element. I do not want a string, as returned by $('#formid').serialize(); , nor do I want the map returned by $('#formid').serializeArra... | <p>How do I convert all elements of my form to a JavaScript object? </p>
<p>I'd like to have some way of automatically building a JavaScript object from my form, without having to loop over each element. I do not want a string, as returned by <code>$('#formid').serialize();</code>, nor do I want the map returned by <c... | [
{
"answerId": 1186309,
"score": 1741,
"isAccepted": true,
"createdAt": "2009-07-27T03:38:41",
"ownerDisplayName": "Tobias Cohen",
"ownerUserId": 66617,
"bodyText": "serializeArray already does exactly that. You just need to massage the data into your required format: function objectifyFo... | 1 |
133925 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/133925/javascript-post-request-like-a-form-submit | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 133,925 | JavaScript post request like a form submit | 1,767 | 1,894,366 | 32 | true | true | [
"javascript",
"forms",
"post",
"submit"
] | 2008-09-25T15:15:43 | 2024-06-12T14:27:44 | Joseph Holsten | false | CC BY-SA 4.0 | 133,997 | 16,981 | 20,948 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I'm trying to direct a browser to a different page. If I wanted a GET request, I might say document.location.href = 'http://example.com/q=a'; But the resource I'm trying to access won't respond properly unless I use a POST request. If this were not dynamically generated, I might use the HTML <form action="http://exampl... | <p>I'm trying to direct a browser to a different page. If I wanted a GET request, I might say</p>
<pre class="lang-js prettyprint-override"><code>document.location.href = 'http://example.com/q=a';
</code></pre>
<p>But the resource I'm trying to access won't respond properly unless I use a POST request. If this were not... | [
{
"answerId": 133997,
"score": 2391,
"isAccepted": true,
"createdAt": "2008-09-25T15:28:53",
"ownerDisplayName": "Rakesh Pai",
"ownerUserId": 20089,
"bodyText": "Dynamically create <input> s in a form and submit it /** * sends a request to the specified url from a form. this will change ... | 1 |
4935632 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/4935632/parse-json-in-javascript | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 4,935,632 | Parse JSON in JavaScript? | 1,763 | 2,026,928 | 16 | true | true | [
"javascript",
"json",
"parsing"
] | 2011-02-08T16:34:03 | 2020-12-18T13:50:33 | user605334 | true | null | 4,935,684 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I want to parse a JSON string in JavaScript. The response is something like var response = '{"result":true,"count":1}'; How can I get the values result and count from this? | <p>I want to parse a JSON string in JavaScript. The response is something like</p>
<pre><code>var response = '{"result":true,"count":1}';
</code></pre>
<p>How can I get the values <code>result</code> and <code>count</code> from this?</p>
| [
{
"answerId": 4935684,
"score": 2044,
"isAccepted": true,
"createdAt": "2011-02-08T16:38:35",
"ownerDisplayName": "Andy E",
"ownerUserId": 94197,
"bodyText": "The standard way to parse JSON in JavaScript is JSON.parse() The JSON API was introduced with ES5 (2011) and has since been imple... | 1 |
432493 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/432493/how-do-you-access-the-matched-groups-in-a-javascript-regular-expression | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 432,493 | How do you access the matched groups in a JavaScript regular expression? | 1,763 | 1,138,745 | 24 | true | true | [
"javascript",
"regex"
] | 2009-01-11T07:21:20 | 2025-02-20T12:02:39 | nickf | false | CC BY-SA 4.0 | 432,503 | 9,021 | 548,320 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I want to match a portion of a string using a regular expression and then access that parenthesized substring: var myString = "something format_abc"; // I want "abc" var arr = /(?:^|\s)format_(.*?)(?:\s|$)/.exec(myString); console.log(arr); // Prints: [" format_abc", "abc"] .. so far so good. console.log(arr[1]); // Pr... | <p>I want to match a portion of a string using a <a href="https://en.wikipedia.org/wiki/Regular_expression" rel="noreferrer">regular expression</a> and then access that parenthesized substring:</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code... | [
{
"answerId": 432503,
"score": 2045,
"isAccepted": true,
"createdAt": "2009-01-11T07:26:02",
"ownerDisplayName": "Christian C. Salvadó",
"ownerUserId": 5445,
"bodyText": "Update: 2019-09-10 The old way to iterate over multiple matches was not very intuitive. This lead to the proposal of ... | 1 |
3895478 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/3895478/does-javascript-have-a-method-like-range-to-generate-a-range-within-the-supp | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 3,895,478 | Does JavaScript have a method like "range()" to generate a range within the supplied bounds? | 1,759 | 1,723,618 | 92 | true | true | [
"javascript",
"arrays",
"functional-programming"
] | 2010-10-09T02:37:29 | 2024-10-20T10:21:31 | alex | false | CC BY-SA 4.0 | 3,895,521 | 31,671 | 492,802 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | In PHP, you can do... range(1, 3); // Array(1, 2, 3) range("A", "C"); // Array("A", "B", "C") That is, there is a function that lets you get a range of numbers or characters by passing the upper and lower bounds. Is there anything built-in to JavaScript natively for this? If not, how would I implement it? | <p>In PHP, you can do...</p>
<pre><code>range(1, 3); // Array(1, 2, 3)
range("A", "C"); // Array("A", "B", "C")
</code></pre>
<p>That is, there is a function that lets you get a range of numbers or characters by passing the upper and lower bounds.</p>
<p>Is there anything built-in to JavaScript natively for this? If... | [
{
"answerId": 10050831,
"score": 2798,
"isAccepted": false,
"createdAt": "2012-04-07T01:05:11",
"ownerDisplayName": "Fuji",
"ownerUserId": 418400,
"bodyText": "Numbers [...Array(5).keys()]; => [0, 1, 2, 3, 4] Character iteration String.fromCharCode(...[...Array('D'.charCodeAt(0) - 'A'.ch... | 1 |
979975 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/979975/get-the-values-from-the-get-parameters-javascript | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 979,975 | Get the values from the "GET" parameters (JavaScript) | 1,756 | 2,912,456 | 63 | true | true | [
"javascript",
"url",
"url-parameters"
] | 2009-06-11T08:32:49 | 2022-08-05T08:02:43 | joe | true | null | 979,995 | 120,457 | 35,257 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I have a URL with some GET parameters as follows: www.test.com/t.html?a=1&b=3&c=m2-m3-m4-m5 I need to get the whole value of c . I tried to read the URL, but I got only m2 . How do I do this using JavaScript? | <p>I have a URL with some GET parameters as follows:</p>
<pre><code>www.test.com/t.html?a=1&b=3&c=m2-m3-m4-m5
</code></pre>
<p>I need to get the whole value of <code>c</code>. I tried to read the URL, but I got only <code>m2</code>. How do I do this using JavaScript?</p>
| [
{
"answerId": 979995,
"score": 2710,
"isAccepted": true,
"createdAt": "2009-06-11T08:37:53",
"ownerDisplayName": "Quentin",
"ownerUserId": 19068,
"bodyText": "JavaScript itself has nothing built in for handling query string parameters. Code running in a ( modern ) browser can use the URL... | 1 |
507138 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/507138/how-to-add-a-class-to-an-html-element-with-javascript | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 507,138 | How to add a class to an HTML element with JavaScript? | 1,753 | 2,835,748 | 28 | true | true | [
"javascript",
"html",
"dom-manipulation"
] | 2009-02-03T13:54:00 | 2026-02-24T06:03:31 | Blankman | false | CC BY-SA 4.0 | 507,157 | 39,677 | 268,914 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I have an element that already has a class: <div class="someclass"> ... </div> How can i add a class to the div (not replace, but add) with JavaScript? | <p>I have an element that already has a class:</p>
<pre class="lang-html prettyprint-override"><code><div class="someclass">
...
</div>
</code></pre>
<p>How can i add a class to the <code>div</code> (not replace, but add) with JavaScript?</p>
| [
{
"answerId": 507157,
"score": 2853,
"isAccepted": true,
"createdAt": "2009-02-03T13:58:01",
"ownerDisplayName": "Ishmael",
"ownerUserId": 8930,
"bodyText": "If you're only targeting modern browsers: Use element.classList.add to add a class: element.classList.add(\"my-class\"); And eleme... | 2 |
5076944 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/5076944/what-is-the-difference-between-null-and-undefined-in-javascript | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 5,076,944 | What is the difference between null and undefined in JavaScript? | 1,752 | 765,647 | 39 | true | true | [
"javascript",
"null",
"undefined"
] | 2011-02-22T10:30:10 | 2024-07-05T22:31:05 | user605334 | false | CC BY-SA 4.0 | 5,076,962 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | What is the difference between null and undefined in JavaScript? | <p>What is the difference between <code>null</code> and <code>undefined</code> in JavaScript?</p>
| [
{
"answerId": 5076962,
"score": 1672,
"isAccepted": true,
"createdAt": "2011-02-22T10:31:56",
"ownerDisplayName": "sebastian",
"ownerUserId": 627938,
"bodyText": "undefined means a variable has been declared but has not yet been assigned a value : var testVar; console.log(testVar); //sho... | 1 |
11508463 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/11508463/javascript-set-object-key-by-variable | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 11,508,463 | JavaScript set object key by variable | 1,748 | 1,486,840 | 9 | true | true | [
"javascript"
] | 2012-07-16T16:24:23 | 2026-04-09T00:53:22 | Hunter McMillen | true | null | 11,508,490 | 702,638 | 61,834 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I am building some objects in JavaScript and pushing those objects into an array, I am storing the key I want to use in a variable then creating my objects like so: var key = "happyCount"; myArray.push( { key : someValueArray } ); but when I try to examine my array of objects for every object the key is "key" instead o... | <p>I am building some objects in JavaScript and pushing those objects into an array, I am storing the key I want to use in a variable then creating my objects like so:</p>
<pre><code>var key = "happyCount";
myArray.push( { key : someValueArray } );
</code></pre>
<p>but when I try to examine my array of objects for ev... | [
{
"answerId": 11508490,
"score": 3089,
"isAccepted": true,
"createdAt": "2012-07-16T16:26:12",
"ownerDisplayName": "gen_Eric",
"ownerUserId": 206403,
"bodyText": "You need to make the object first, then use [] to set it. var key = \"happyCount\"; var obj = {}; obj[key] = someValueArray; ... | 1 |
13789618 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/13789618/differences-between-lodash-and-underscore-js | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 13,789,618 | Differences between Lodash and Underscore.js | 1,729 | 373,953 | 12 | true | true | [
"underscore.js",
"javascript",
"lodash"
] | 2012-12-09T17:08:36 | 2022-10-14T19:08:01 | Brian M. Hunt | true | null | 13,898,916 | 19,212 | 84,602 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | Why would someone prefer either the Lodash or Underscore.js utility library over the other? Lodash seems to be a drop-in replacement for underscore, the latter having been around longer. I think both are brilliant, but I do not know enough about how they work to make an educated comparison, and I would like to know mor... | <p>Why would someone prefer either the <a href="http://lodash.com/" rel="noreferrer">Lodash</a> or <a href="http://underscorejs.org/" rel="noreferrer">Underscore.js</a> utility library over the other?</p>
<p>Lodash seems to be a drop-in replacement for underscore, the latter having been around longer.</p>
<p>I think bo... | [
{
"answerId": 13898916,
"score": 2173,
"isAccepted": true,
"createdAt": "2012-12-16T05:34:06",
"ownerDisplayName": "John-David Dalton",
"ownerUserId": 166625,
"bodyText": "I created Lodash to provide more consistent cross-environment iteration support for arrays, strings, objects, and ar... | 1 |
979256 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/979256/sorting-an-array-of-objects-by-property-values | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 979,256 | Sorting an array of objects by property values | 1,727 | 1,639,463 | 27 | true | true | [
"javascript",
"arrays",
"sorting"
] | 2009-06-11T03:59:54 | 2025-01-03T06:24:26 | TomHankers | false | CC BY-SA 4.0 | 979,289 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I've got the following objects using AJAX and stored them in an array: var homes = [ { "h_id": "3", "city": "Dallas", "state": "TX", "zip": "75201", "price": "162500" }, { "h_id": "4", "city": "Bevery Hills", "state": "CA", "zip": "90210", "price": "319250" }, { "h_id": "5", "city": "New York", "state": "NY", "zip": "0... | <p>I've got the following objects using AJAX and stored them in an array:</p>
<pre><code>var homes = [
{
"h_id": "3",
"city": "Dallas",
"state": "TX",
"zip": "75201",
"price": "162500"
}, {
"h_id": "4",
"city": "Bevery Hills",
"state": "CA",
... | [
{
"answerId": 979289,
"score": 2232,
"isAccepted": true,
"createdAt": "2009-06-11T04:12:35",
"ownerDisplayName": "Stobor",
"ownerUserId": 43452,
"bodyText": "Sort homes by price in ascending order: homes.sort(function(a, b) { return parseFloat(a.price) - parseFloat(b.price); }); Or after... | 1 |
1911015 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/1911015/how-do-i-debug-node-js-applications | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 1,911,015 | How do I debug Node.js applications? | 1,715 | 568,328 | 42 | true | true | [
"javascript",
"node.js",
"debugging",
"google-chrome-devtools"
] | 2009-12-15T22:50:07 | 2023-06-25T18:29:01 | Fabian Jakobs | false | CC BY-SA 3.0 | 2,536,734 | 129,322 | 29,183 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | How do I debug a Node.js server application? Right now I'm mostly using alert debugging with print statements like this: sys.puts(sys.inspect(someVariable)); There must be a better way to debug. I know that Google Chrome has a command-line debugger. Is this debugger available for Node.js as well? | <p>How do I debug a Node.js server application?</p>
<p>Right now I'm mostly using <em>alert debugging</em> with print statements like this:</p>
<pre><code>sys.puts(sys.inspect(someVariable));
</code></pre>
<p>There must be a better way to debug. I know that <a href="http://en.wikipedia.org/wiki/Google_Chrome" rel="n... | null | 0 |
523643 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/523643/difference-between-and-in-javascript | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 523,643 | Difference between == and === in JavaScript | 1,711 | 1,054,703 | 2 | true | true | [
"javascript",
"comparison-operators",
"equality-operator",
"identity-operator"
] | 2009-02-07T11:53:04 | 2025-06-24T21:28:52 | Shiva | true | null | 523,647 | 51,570 | 18,293 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | What is the difference between == and === in JavaScript? I have also seen != and !== operators. Are there more such operators? | <p>What is the difference between <code>==</code> and <code>===</code> in JavaScript? I have also seen <code>!=</code> and <code>!==</code> operators. Are there more such operators?</p>
| [
{
"answerId": 523650,
"score": 2041,
"isAccepted": false,
"createdAt": "2009-02-07T11:57:35",
"ownerDisplayName": "sdfx",
"ownerUserId": 3445,
"bodyText": "Take a look here: http://longgoldenears.blogspot.com/2007/09/triple-equals-in-javascript.html The 3 equal signs mean \"equality with... | 1 |
14667713 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/14667713/how-to-convert-a-string-to-number-in-typescript | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 14,667,713 | How to convert a string to number in TypeScript? | 1,708 | 2,808,282 | 22 | true | true | [
"javascript",
"typescript"
] | 2013-02-02T23:34:18 | 2025-09-26T09:44:15 | Paul0515 | false | CC BY-SA 4.0 | 14,668,510 | 1,627,079 | 25,745 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | Given a string representation of a number, how can I convert it to number type in TypeScript? var numberString: string = "1234"; var numberValue: number = /* what should I do with `numberString`? */; | <p>Given a string representation of a number, how can I convert it to <code>number</code> type in TypeScript?</p>
<pre><code>var numberString: string = "1234";
var numberValue: number = /* what should I do with `numberString`? */;
</code></pre>
| [
{
"answerId": 14668510,
"score": 2503,
"isAccepted": true,
"createdAt": "2013-02-03T01:19:52",
"ownerDisplayName": "Ryan Cavanaugh",
"ownerUserId": 1704166,
"bodyText": "Exactly like in JavaScript , you can use the parseInt or parseFloat functions, or simply use the unary + operator: var... | 2 |
847185 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/847185/convert-a-unix-timestamp-to-time-in-javascript | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 847,185 | Convert a Unix timestamp to time in JavaScript | 1,690 | 2,705,730 | 35 | true | true | [
"javascript",
"date",
"time",
"time-format"
] | 2009-05-11T08:23:28 | 2024-02-05T12:13:20 | roflwaffle | false | CC BY-SA 4.0 | 847,196 | 49,887 | 30,792 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I am storing time in a MySQL database as a Unix timestamp and that gets sent to some JavaScript code. How would I get just the time out of it? For example, in HH/MM/SS format. | <p>I am storing time in a MySQL database as a Unix timestamp and that gets sent to some JavaScript code. How would I get just the time out of it?</p>
<p>For example, in <code>HH/MM/SS</code> format.</p>
| [
{
"answerId": 847196,
"score": 2367,
"isAccepted": true,
"createdAt": "2009-05-11T08:28:50",
"ownerDisplayName": "Aron Rotteveel",
"ownerUserId": 11568,
"bodyText": "let unix_timestamp = 1549312452; // Create a new JavaScript Date object based on the timestamp // multiplied by 1000 so th... | 1 |
497094 | question | stackoverflow | 2026-08-03T01:37:30 | null | null | null | null | null | https://stackoverflow.com/questions/497094/how-do-i-find-out-which-dom-element-has-the-focus | gRfaNe5dFEERAlPiJ | OOGxFG8S0YK0PA8Ta | 497,094 | How do I find out which DOM element has the focus? | 1,690 | 990,992 | 22 | true | true | [
"javascript",
"dom"
] | 2009-01-30T20:21:31 | 2024-10-15T00:42:53 | Tony Peterson | false | CC BY-SA 4.0 | 497,108 | 26,140 | 21,364 | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | I would like to find out, in JavaScript, which element currently has focus. I've been looking through the DOM and haven't found what I need, yet. Is there a way to do this, and how? The reason I was looking for this: I'm trying to make keys like the arrows and enter navigate through a table of input elements. Tab works... | <p>I would like to find out, in JavaScript, which element currently has focus. I've been looking through the DOM and haven't found what I need, yet. Is there a way to do this, and how?</p>
<p>The reason I was looking for this:</p>
<p>I'm trying to make keys like the arrows and <code>enter</code> navigate through a ta... | [
{
"answerId": 497108,
"score": 1985,
"isAccepted": true,
"createdAt": "2009-01-30T20:24:55",
"ownerDisplayName": "JW.",
"ownerUserId": 4321,
"bodyText": "Use document.activeElement , it is supported in all major browsers. Previously, if you were trying to find out what form field has foc... | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.