Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 1 year ago. The community reviewed whether to reopen this question 12 days ago and left it closed: Origi…
Tag: javascript
Javascript – maintain key order when going from object -> array
I know key order isn’t guaranteed in JS objects, however, my data structure comes from a backend for which I have no control over. Is there anything I can do to preserve the key order when going from: to: It’s of the utmost importance that I keep the key order unfortunately… Answer No. As yo…
Chrome Extensions – Button in popup.html
First, i’m no professional programmer, just playing a little bit around. I tried to write a little Chrome Extension to manage other Extensions. But i already failed to create a button, on which i can click an something happens. My main problem is, that while trying to get the elementbyid, it returns NUL…
How to assign JSON string to Javascript variable?
What is the correct way to assign a JSON string to a variable? I keep getting EOF errors. http://jsfiddle.net/x7rwq5zm/1/ Answer You have not escaped properly. You make sure you do: The easier way would be to just convert an existing object to a string using JSON.stringify(). Would recommend this as much as p…
Using Node.js require vs. ES6 import/export
In a project I am collaborating on, we have two choices on which module system we can use: Importing modules using require, and exporting using module.exports and exports.foo. Importing modules using ES6 import, and exporting using ES6 export Are there any performance benefits to using one over the other? Is …
What’s the most performant way to do simple IP address comparisons?
I’m working in node.js, and I want to do something like the following pseudocode… Any ideas on the fastest way to do this? I’ve already checked out cidr-js, and it provides functionality for CIDR conversions but not IP address comparisons. Seems like node-ip could be a good choice. Thanks! A…
How to convert seconds to HH:mm:ss in moment.js
How can I convert seconds to HH:mm:ss? At the moment I am using the function below This works on chrome but in firefox for 12 seconds I get 01:00:12 I would like to use moment.js for cross browser compatibility I tried this but does not work What am I doing wrong? EDIT I managed to find a solution without mom…
javascript module pattern from You don’t know JS
I have been reading and testing below code out for several hours now and I just can’t seem to grasp certain things. I have been stepping through chrome console basically putting break in every line I can add and have been inspecting and I am just not sure of things 1)I am just not sure of the purpose of…
Why JavaScript is not working in HTTPS on my site
I have just added HTTPS to my site and apparently the only script I have on my site has stopped working. I don’t think it is a problem of the script, but here it is: What is the solution to this problem? Answer Add your jQuery file like this, without mentioning the protocol explicitly: Removing the http…
Javascript function challenge add(1,2) and add(1)(2) both should return 3
A friend of mine challenged me to write a function that works with both of these scenarios My instinct was the write an add() function that returns itself but I’m not sure I’m heading in the right direction. This failed. So I started reading up on functions that return other functions or return th…