Skip to content

Tag: javascript

Generic deep diff between two objects

I have two objects: oldObj and newObj. The data in oldObj was used to populate a form and newObj is the result of the user changing data in this form and submitting it. Both objects are deep, ie. they have properties that are objects or arrays of objects etc – they can be n levels deep, thus the diff al…

How to start and stop/pause setInterval?

I’m trying to pause and then play a setInterval loop. After I have stopped the loop, the “start” button in my attempt doesn’t seem to work : Is there a working way to do this? Answer The reason you’re seeing this specific problem: JSFiddle wraps your code in a function, so start(…

Make a number a percentage

What’s the best way to strip the “0.”XXX% off a number and make it a percentage? What happens if the number happens to be an int? Answer A percentage is just: No need for anything fancy:

JS search in object values

I have an array of homogeneous objects like so; I’d like to search these objects’ values (not keys) with a keyword, and return an array of objects that contain the keyword in any of the values. So for example, with a keyword r, I would get all the objects (“baR” in object #1, “lo…

Javascript sort not working in Firefox

I have the following code which is sorting a list of javascript objects in an array based on their date. The data is coming from an XML file. The date is formatted as follows: MM-DD-YYYY So at this stage I have a load of concert objects in my concerts array. I then go to sort it and output it to

Insert content at top of page without scrolling

Is there a way that I can insert content at the beginning of a webpage without causing the page to give the impression of scrolling up. I’m trying to implement something kind of like infinite scrolling but I need to be able to scroll up infinitely as well as down (I’m also unloading content on the…

trouble with recursion; parsing JSON

I have a json object like this: …and I’m trying to iterate through it and get a total count on the “text” objects. I can’t seem to be able to get something recursive working.. I think I’m missing a base-level understanding of both json and recursion.. After a couple of days…