All Questions

-7
votes
2answers
32819 views

How to avoid ArrayIndexOutOfBoundsException or IndexOutOfBoundsException?

If your question is I am getting a java.lang.ArrayIndexOutOfBoundsException in my code and I do not understand why it is happening. What does it mean and how can I avoid it? This is meant to be th...
3467
votes
23answers
3095391 views

For-each over an array in JavaScript?

How can I loop through all the entries in an array using JavaScript? I thought it was something like this: forEach(instance in theArray) Where theArray is my array, but this seems to be incorrect....
811
votes
28answers
555999 views

How to create a generic array in Java?

Due to the implementation of Java generics, you can't have code like this: public class GenSet<E> { private E a[]; public GenSet() { a = new E[INITIAL_ARRAY_LENGTH]; // error:...
1582
votes
31answers
750148 views

Sort array of objects by string property value in JavaScript

I have an array of JavaScript objects: var objs = [ { first_nom: 'Lazslo', last_nom: 'Jamf' }, { first_nom: 'Pig', last_nom: 'Bodine' }, { first_nom: 'Pirate', last_nom: 'Prenti...
809
votes
5answers
554653 views

Sort Multi-dimensional Array by Value

How can I sort this array by the value of the "order" key? Even though the values are currently sequential, they will not always be. Array ( [0] => Array ( [hashtag] => ...
2973
votes
39answers
2003879 views

How do I check if an array includes an object in JavaScript?

What is the most concise and efficient way to find out if a JavaScript array contains an object? This is the only way I know to do it: function contains(a, obj) { for (var i = 0; i < a.length...
225
votes
15answers
262266 views

How to find the 'sizeof' (a pointer pointing to an array)?

First off, here is some code: int main() { int days[] = {1,2,3,4,5}; int *ptr = days; printf("%u\n", sizeof(days)); printf("%u\n", sizeof(ptr)); return 0; } Is there a way to ...
950
votes
22answers
682260 views

Sorting an array of JavaScript objects

I read the following objects using Ajax and stored them in an array: var homes = [ { "h_id": "3", "city": "Dallas", "state": "TX", "zip": "75201", "price":...
1355
votes
15answers
76064 views

With arrays, why is it the case that a[5] == 5[a]?

As Joel points out in Stack Overflow podcast #34, in C Programming Language (aka: K & R), there is mention of this property of arrays in C: a[5] == 5[a] Joel says that it's because of pointer ari...
714
votes
55answers
689622 views

Remove duplicate values from JS array

I have a very simple JavaScript array that may or may not contain duplicates. names = new Array("Mike","Matt","Nancy","Adam","Jenny","Nancy","Carl"); I need to remove the duplicates and put the uni...

Previous Next