Skip to content
Advertisement

Tag: arrays

looping through arrays of arrays

I have an arrays of arrays (some thing like graph), How to iterate all arrays? Its just an example array, actual can contains any number of array and then arrays. How to print all those numbers? Its similar to html objects DOM Answer This recursive function should do the trick with any number of dimensions:

Sending Javascript Object to PHP via Ajax

I’m learning Ajax by failure and have hit a wall: I have an array (if it matters, the array is storing number id’s based on what checkboxes the user checks) that is written in Javascript. I have a function that is called when the user clicks the ‘save’ button. The function is as follows: My question is: What can I

Unlimited arguments in a JavaScript function

Can a JavaScript function take unlimited arguments? Something like this: I am trying: But this doesn’t work (output is only the first argument). Or the only way is: Thanks Answer There’s a weird “magic” variable you can reference called “arguments”: It’s like an array, but it’s not an array. In fact it’s so weird that you really shouldn’t use it

How to know if two arrays have the same values

I have these two arrays: one is filled with information from an ajax request and another stores the buttons the user clicks on. I use this code (I filled with sample numbers): But it always gives false, even if the two arrays are the same, but with different name. (I checked this in Chrome’s JS Console). So, is there any

RegEx to match stuff between parentheses

I’m having a tough time getting this to work. I have a string like: And I need regex or a method of getting each match between the parentheses and return an array of matches like: The regex I’m using is /((.+))/ which does seem to match the right thing if there is only one set of parenthesis. How can I

How to replace item in array?

Each item of this array is some number: How to replace some item with a new one? For example, we want to replace 3452 with 1010, how would we do this? Answer Also it is recommend you not use the constructor method to initialize your arrays. Instead, use the literal syntax: You can also use the ~ operator if you

Create an array with random values

How can I create an array with 40 elements, with random values from 0 to 39 ? Like I tried using solutions from here: http://freewebdesigntutorials.com/javaScriptTutorials/jsArrayObject/randomizeArrayElements.htm but the array I get is very little randomized. It generates a lot of blocks of successive numbers… Answer Here’s a solution that shuffles a list of unique numbers (no repeats, ever). If you want

How to initialize an array’s length in JavaScript?

Most of the tutorials that I’ve read on arrays in JavaScript (including w3schools and devguru) suggest that you can initialize an array with a certain length by passing an integer to the Array constructor using the var test = new Array(4); syntax. After using this syntax liberally in my js files, I ran one of the files through jsLint, and

Advertisement