Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options answers only not deleted user 23727

JavaScript is a versatile, high-level programming language. It is the programming language in all browsers.and can be used for back-end programming with node.js. Use this tag for questions regarding vanilla JavaScript; optionally tagged with an ECMAScript version. If you are using a preprocessor such as TypeScript please tag with that too.

6 votes
Accepted

Calculating quiz score, with weights and partial credit

. // now let's set a user answer on a question // we can assume that we get both the question index // and the answer index for the question from elsewhere in javascript // for example from clicking on … In a real application you may also add something like a quiz rendering class to be able to render the quiz using javascript (and to separate display of quiz from core quiz objects). …
Mike Brant's user avatar
  • 9,638
0 votes
Accepted

Simple JS XMLHttp wrapper class

I am concerned that you have added a layer of false generalization around a very specific, usually one-time use, request object. I would think the class would be better named Request or similar to be …
Mike Brant's user avatar
  • 9,638
0 votes

Extension of JavaScript "typeof"

Outside of the other answers about the general utility of this function, I figured I would add some additional thoughts on the code itself. I do agree with those other opinions though that this functi …
Mike Brant's user avatar
  • 9,638
3 votes
Accepted

When push data to array decide which key need to use

A few thoughts: First, you might consider whether the name/color property REALLY needs to change as output here. Why return { color: ... } in some cases and { name: ... } in others? This tends to i …
Mike Brant's user avatar
  • 9,638
1 vote

Getting an array of certain objects within an object

Your nested "ifs" make the code very hard to read. I would think about changing your approach to something like if (undefined === vm.masterFormObject) { console.log('Some error message.'); r …
Mike Brant's user avatar
  • 9,638
0 votes

Comparing version numbers contained in a text string

I would consider formulating the output for this custom function to return values of 1, 0, and -1 (a typical javascript approach for comparing two values), such that this function could be used as a custom …
Mike Brant's user avatar
  • 9,638
3 votes
Accepted

Flattening array in Javascript

I would think that this might be a problem best solved via recursion. For example: function flattenArray(arr) { var result = []; arr.forEach(function($val) { if(Array.isArray($val)) …
Mike Brant's user avatar
  • 9,638
3 votes

Data Layer Object Getter and Setter by Path

I guess I don't really see what value you are getting from these functions. Isn't the following in essence the same thing without ~100 extra lines of code that don't really do much other than provid …
Mike Brant's user avatar
  • 9,638
3 votes

Deep Clone Objects

I would agree with answer from @JosephtheDreamer that, as a beginner in javascript, this is probably a domain area you don't want to tackle unless your intent is just to deep clone simple array and object … I would also strongly suggest that, if you are just learning javascript, you do so based on ES6 and get familiar with that syntax. …
Mike Brant's user avatar
  • 9,638
6 votes
Accepted

First attempt at a pure JavaScript slider

That might look like this: (function() { // your javascript code }()) This would prevent you from defining a bunch of variables in global scope which could interact negatively with other javascript
Mike Brant's user avatar
  • 9,638
8 votes
Accepted

Multiply all elements in an array except one

product * value, 1); return numbers.map( (value) => arrayProduct / value ); } One could also easily foresee a case where larger arrays could easily hit up against the Number.MAX_SAFE_INTEGER value in javascript
Mike Brant's user avatar
  • 9,638
2 votes

Using a loose array just to specify the object properties

I think I would consider something like this: const data = { teaching_levels: null, axes: null, accessibility_resources: null, contents: null, resources: null, licenses: resul …
Mike Brant's user avatar
  • 9,638
5 votes

Array to key/value JSON conversion

Not sure that a class definition makes a lot of sense here since you don’t really have any real behavior being defined in this class. Destructuring can also help you populate variables from the inpu …
Mike Brant's user avatar
  • 9,638
2 votes

A JavaScript isEven() function, defined recursively

Both of these seem horribly inefficient, but I guess that is what you get if you are forced to use recursion to solve this problem. In either case you don't validate input. What if you don't get an …
Mike Brant's user avatar
  • 9,638
3 votes
Accepted

Getting path array for given value in nested Object

Some thoughts: This is not truly a recursive function, in that you are not passing the path value when first calling the function. This may hint that you should really just recurse privately within …
Mike Brant's user avatar
  • 9,638

1
2 3 4 5
9
15 30 50 per page