Skip to content

Author: admin@master

How to make a promise from setTimeout

This is not a realworld problem, I’m just trying to understand how promises are created. I need to understand how to make a promise for a function that returns nothing, like setTimeout. Suppose I have: How do I create a promise that async can return after the setTimeout is ready to callback()? I suppose…

Binary Search in Javascript

I’m trying to implement a binary search algorithm in JavaScript. Things seem okay, but my return statements appear to be returning undefined. Can anybody tell me what’s wrong here? Fiddle: http://jsfiddle.net/2mBdL/ Answer You’re not explicitly returning the recursive inner calls (i.e. retur…

React.js: onChange event for contentEditable

How do I listen to change events for a contentEditable-based control? Code on JSFiddle. Answer See Sebastien Lorber’s answer which fixes a bug in my implementation. Use the onInput event, and optionally onBlur as a fallback. You might want to save the previous contents to prevent sending extra events. I…

Remove duplicate objects from JSON file in JavaScript

This is the current JSON file: I want to remove the duplicate Steve individual from the list. How can I make a new JSON that checks if the object’s name matches and remove any duplicates in JavaScript? Answer You must load the JSON data in to the program and parse that with JSON.parse, like this To filt…

Getting the url parameters inside the html page

I have a HTML page which is loaded using a URL that looks a little like this: I would like to obtain the query string parameters in the URL without using a jsp. Questions Can this be done using Javascript or jQuery? Because I want to test my page using my Node.js local server before deploying it in the remote

Failed to execute ‘atob’ on ‘Window’

I’m trying to save my HTML file in Chrome when the user presses ctrl + s keys but Chrome is crashed. (I want to download just the source code of my HTML file) I read that it happens because my file is bigger than 1.99M.. In the first attempt (before I knew about the crashing in Chrome): The second attem…

Browser-Based SRP without Java

I am considering implementing the Secure Remote Password protocol to conduct a zero-knowledge password proof between the browser and my web application. The SRP website provides an example, but it requires java to perform calculations. I am wondering whether it is possible to implement SRP using javascript wi…

How to get all pairs of array JavaScript

I need to call function with all avaliable pairs of array elements. Like this: Answer You should try to show us that you’ve solved the problem yourself instead of just asking us for the answer, but it was an interesting problem, so here: http://jsfiddle.net/J3wT5/