I have a 2 dimensional array albumPhotos[x][y]. The rows are photoalbums and the columns are links to photos. Now every photoalbum has a different number of photos , that means that every row in this array has a different number of columns. I am trying to check whats the length of every row in this array , that means how
Tag: arrays
Javascript ascii string to hex byte array
I am trying to convert an ASCII string into a byte array. Problem is my code is converting from ASCII to a string array and not a Byte array: This results in: But what I am looking for is: How can I convert to a byte rather than a byte string ? This array is being streamed to a USB
Sort array on key value
I have a function which sorts by name currently and an array of value / key pairs. I wonder how can I pass the key on which sort is being performed so I can call the same function every time like so: Answer [edit 2020/08/14] This was rather an old answer and not very good as well, so simplified and
appending array to FormData and send via AJAX
I’m using ajax to submit a multipart form with array, text fields and files. I append each VAR to the main data as so then I use the ajax function to send it to a PHP file to store inside sql DB. But on the PHP side, the arr variable, which is an array appears as a string. When I
Javascript reduce() on Object
There is nice Array method reduce() to get one value from the Array. Example: What is the best way to achieve the same with objects? I’d like to do this: However, Object does not seem to have any reduce() method implemented. Answer What you actually want in this case are the Object.values. Here is a concise ES6 implementation with that
Javascript call() & apply() vs bind()?
I already know that apply and call are similar functions which set this (context of a function). The difference is with the way we send the arguments (manual vs array) Question: But when should I use the bind() method ? jsbin Answer I created this comparison between function objects, function calls, call/apply and bind a while ago: .bind allows you
How to select all other values in an array except the ith element?
I have a function using an array value represented as How can I select all other values in an array except this one? The purpose of this is to reset all other Google Maps images to their original state but highlight a new one by changing the image. Answer Use Array.prototype.splice to get an array of elements excluding this one.
2-dimensional array to object (JavaScript)
I have an array, that holds a large number of two-dimensional arrays: I need to convert this array into an object of the following form to send it as JSON: (“s_id” should be myArray[0][0], “t_id myArray[0][1], and “type” myArray[0][2] and so on.) How can I get the array in the desired form? Thanks in advance. Answer Be aware that map
Can I append an array to ‘formdata’ in javascript?
I’m using FormData to upload files. I also want to send an array of other data. When I send just the image, it works fine. When I append some text to the formdata, it works fine. When I try to attach the ‘tags’ array below, everything else works fine but no array is sent. Any known issues with FormData and
Javascript – sort array based on another array
Is it possible to sort and rearrange an array that looks like this: to match the arrangement of this array: Unfortunately, I don’t have any IDs to keep track on. I would need to priority the items-array to match the sortingArr as close as possible. Update: Here is the output I’m looking for: Any idea how this can be done?