Tag: arrays

mimic C array of struct processing in JavaScript performancewise

In C it is possible to get a large amount of data records of mixed type processed quite effective. For example, compute a record as function of another like: struct TypeA{ int i; boolean b; } struct TypeA{ long int l; float f; } struct TypeA as[1000]; struct TypeB bs[1000]; for(int i=0; i<1000; i++) bs[i]=someFunction(as[i]); […]

How to end .empty()

i have an array(allArr) of arrays on a function,first time array from position 0 from allArr is taken with image from position 0 from another array with images (named image) ’cause of document.ready then by clicking on a button (id=”nextimageandshuffle”) arrays from allArr and images from image array reach fifth.My problem is that everytime i […]

javascript/jQuery How do I reuse objects in an array for a particle system

I’m in the process of building an entity system for a canvas game. This started from a simple particle emitter/updater which I am altering to accommodate a multi-particle/entity generator. Whilst i am usually ok with javascript/jQuery I am running into the limits of my experience as it concerns arrays and would gratefully accept any help […]

Javascript: fill missing values between arrays

I am looking for a high-performance way to zero-fill values that are mutually exclusive between two arrays. This data is for a JS chart that must have entries for every x-value. An example may explain this better: Before: obj1 = [{x:1, y:1}, {x:3, y:2}]; obj2 = [{x:2, y:2}, {x:4, y:4}]; After: obj1 = [{x:1, y:1}, […]

Create Ember objects from JSON response and display with Handlebars

I’m attempting to use Ember to query a JSON API, create Objects out of the data, and then loop through the objects in my Handlebars templates. I’m able to log the response as well as the categories array and I see them both being created. I keep getting “No categories found” in my template. app.js: […]

Why is JavaScript Array Loop printing extra line?

The following is supposed to print the 4 names like so: alice bob michelle timmy Code: function Person (name, age) { this.name = name; this.age = age; } family = new Array(); family[0] = new Person (“alice”, 40); family[1] = new Person (“bob”, 42); family[2] = new Person (“michelle”, 8); family[3] = new Person (“timmy”, […]

How do I define QML states dynamically using JavaScript

Is there any way of creating a state object dynamically using a javascript loop for instance. Result should look like: states: [ State{ name: “name1” when: somevar === onevar //stuff }, State{ name: “name2” when: somevar === anothervar //stuff } ] but I want to start with an arbitrary javascript array, like var myStatesObj = […]

How to use PHP variable in an external Javascript

I am trying use an array created in PHP in my external javaScript. I have PHP code that puts images from the directory depending on the userid given via url, into an array and I want to be able to use this array in javaScript so that I can create a photo slideshow and have […]

JavaScript array values turned to undefined when not debugging in IE11

I have written a very simple partition function in JavaScript: Array.prototype.partition = function (size, step) { var out = []; for (var i = 0; i < this.length – size; i += step) { var tmp = this.slice(i, i + size); //two lines below were for quick debug //console.log(tmp); //console.log(out); out.push(tmp); } return out; }; […]

How to find first key “id” on the page in AngularJS?

I would like to find the first id of the index of the first ng-repeat on the page. without jQuery and use this value and store inside a new $scope.firstId. I need the value in the view. EDIT : I need this value to play the first id found on the page. I have three […]