Tag: arrays

Add multiple numbers to Array

I have two arrays. They look like this: array price = 14.60, 39.00 and array quantity = 10, 5 (quantity is the quantity of items the user want to buy – 10 items from productA and 5 of productB) Now I want loop through the variables to multiply the price with the quantity. Like : […]

JavaScript – Combine two arrays item by item

I have two arrays of arrays where the first contains the location name and the second contains the location latitude and longitude values. Each item in each array corresponds to it’s counterpart in the other and both arrays have the same number of items like so: var arr1 = [[‘Location #1’],[‘Location #2’]]; var arr2 = […]

Alerting Javascript array object shows empty

I am trying to send the JavaScript array to my php, but php gets empty []. It even shows like that in my browser. I have always sent JSON and had no problem, but now have this format. I have this example that makes no sense…it’s just a code to illustrate the issue: var blah […]

Converting javascript dictionary to array/object to be passed in jquery.params

I have a javascript variable which is a dictionary of key-values pairs of querystring. I need to again convert this dictionary into a query string. I am using jquery.param functin but it takes either an array or an object. How can I convert my dictinoary variable to array/object which jquery.params can accept. Tried using serializeArray […]

Javascript for/in loops through properties, not indexes and returns strings

Ok, I have this code: var room = [ { time: 0, people: 0 } ]; and then: time = 5; for( var i in room ) { if( room[i].time < time ){ spliceIndex = i + 1; } } console.log(spliceIndex); And the console reads: 01 – Which means the 1 is concatenated which further […]

Prevent initial array from sorting

I have an array where the order of the objects is important for when I finally output the array in a document. However, I’m also sorting the array in a function to find the highest value. The problem is that I after I run the function to find the highest value, I can’t get the […]

Array issue using JS

Problem was a duplicate, sorry.

[].map.call() VS Array.prototype.map.call()?

Why would one be preferred over the other? [].map.call(…) Array.prototype.map.call(…) Doing a quick test in jsPerf shows the Array.prototype way is more performant, although I read somewhere that jsPerf results can be deceiving. Not here to debate jsPerf, rather, just looking for some insight on why one would be preferred over the other. Thanks!

Combining arrays for use cases

Node.js app, writing validation tests. Given the following: var obj = { foo: null, bar: null, baz: null}, values = [ 0, 1]; I need to create n number of objects to account for every property being assigned every combination of possible values, to represent every possible use case. So for this example, the output […]

How to check multiple checkboxes with JavaScript?

I have multiple checkboxes <div class=”data”> <span> <input name=”employee” type=”checkbox” value=”Alex”/> <label for=”employee”>Alex</label> </span> <span> <input name=”employee” type=”checkbox” value=”Frank”/> <label for=”employee”>Frank</label> </span> <span> <input name=”employee” type=”checkbox” value=”Mark”/> <label for=”employee”>Mark</label> </span> </div> How to find all checked checkboxes and create json or array with result of checking?