Most voted "array" questions
An array (array, vector, or matrix) is an ordered data structure representing a collection of elements (values or variables), each identified by one or multiple indices.
Learn more…3,046 questions
Sort by count of
-
51
votes6
answers15594
viewsHow to do a search ignoring Javascript accent?
Suppose I have a list of words, in Javascript (if necessary, already ordered according to the rules of collation): var palavras = [ "acentuacao", "divagacão", "programaçao", "taxação" ]; Notice I…
-
48
votes6
answers18641
viewsWhat is the difference between declaring an array with "array()" and "[]" in Javascript?
In Javascript we can declare an array in two ways: var matriz = new Array(); and var matriz = []; What is the difference between the two and what the consequences are? This question is being asked…
-
45
votes6
answers2425
viewsArrays are pointers, right?
After all, in C, an array a[] becomes a pointer *a? If not, what are arrays? What are the differences between them? How arrays work internally?
-
31
votes6
answers7015
viewsHow to get unique values in a Javascript array?
In PHP, when I have one array with duplicated values, it is possible to obtain only unique values through the function array_unique. Example: $array = ['a', 'b', 'b', 'c', 'c'];…
-
29
votes6
answers66760
views"foreach" in Javascript
By way of example, in PHP we have the function foreach() (English) which allows us to execute a certain code for each element found in a matrix: <?php $arr = array(1, 2, 3, 4, 5, 6); foreach…
-
23
votes2
answers8037
viewsArraylist x List
What is the difference of declaring ArrayList and List for lists in Java? What are the advantages of using one or the other?
-
23
votes7
answers620
viewsHow to access a circular array?
Whereas I have a array: const a = ['A', 'B', 'C']; I would like to create a function that returns an item and, with each call, returns the subsequent one, and when it comes to the end, returns the…
-
22
votes3
answers1767
viewsWhat prevents an array from being initialized with a variable size in C?
Why does an array need to have a constant size? What prevents it from having a variable size?
-
21
votes2
answers4166
viewsWhat is the difference between array and matrix?
After seeing arrays and programming matrices, I got a little confused, so I was wondering, what’s the difference between a array and a matrix?
-
20
votes3
answers523
viewsWhy does C array[6] equal 6[array]?
Note: Question I saw in ONLY in English, but I found it interesting to put here (because we still don’t have many questions of C): Because in the C language, this code prints "true"? #include…
-
20
votes5
answers2915
viewsWhat is actually the array?
Initially, it seems a silly question. But my goal here is to come up with a more concrete concept regarding the array. In languages such as Javascript, the array is an object that accepts you to add…
-
19
votes4
answers955
viewsHow does Current function work?
For some time I always use the function current() in PHP, to get the first element of array (which is actually not its functionality, as it returns the current pointer on which the array is) and…
-
17
votes3
answers3083
viewsHow to do a search ignoring Python accent?
Suppose I have a list of words, in Python (if necessary, already ordered according to the rules of collation): palavras = [ u"acentuacao", u"divagacão", u"programaçao", u"taxação", ] Notice I didn’t…
-
17
votes2
answers2365
viewsAre JS native objects associative arrays?
And the arrays are like native objects of JS? What about literal strings/primitive data? What I understand is that they are instances of the object string, but with the difference of being arrays…
-
17
votes2
answers1267
viewsWhat is the difference between String[] args and String args[]?
What is the difference between the statements String[] args and String args[] in Java?
-
16
votes3
answers4097
viewsHow to randomly color Divs with a Javascript Color Array?
I created a function that changes colors (pulled from one array) on certain page elements (which are also on array), but it was very strange, as it changes the colors of the elements one after the…
-
16
votes2
answers669
viewsWhat are the advantages of using associative arrays?
I came across the definition of associative arrays which are vectors with indices consisting of strings, example: $site['nome'] = "Stack Overflow"; What are the advantages of using this type of…
-
16
votes3
answers1114
viewsWorking with lists without using Array() in PHP
I know that in PHP for almost every kind of list, we work with Array(), but this would be the only way to work with PHP lists? Is there any other way to work with PHP object lists, like the…
-
16
votes3
answers8395
viewsDeserialize JSON Array in an Object Array
Good afternoon, I decided to ask because I’ve been holding on to this for three days and as much as I’ve looked, I haven’t found a solution to my problem. Access a Web Service via C#, Httpclient,…
-
16
votes2
answers11240
viewsDifference between splice() and Slice()
What is the difference between the functions splice() and slice() of the object Array of JavaScript and when each shall be used?
-
15
votes3
answers1932
viewsIs there a more efficient way to create an array from another array dynamically, filtering the contents of the first one?
I have an array of values that can include several numpy.Nan: import numpy as np a = np.array ( [1, 2, np.nan, 4] ) And I want to iterate over your items to create a new array without np.Nan. The…
-
15
votes1
answer2705
viewsHow to sort array of strings disregarding accents?
If I have an array like the following: exemplo = ["Árvore", "Casa", "Computador", "É", "Poste", "Pássaro", "Índia", "Ar", "Ásia"] The exemplo.sort() considers the accentuation of the words to order,…
-
15
votes3
answers1089
viewsWhat are the pros and cons of indexing vectors by zero or one?
Most programming languages I know have zero as the first index of a vector. I know that several programming languages have content um as the first vector index. Until recently I thought this was…
-
14
votes6
answers1877
viewsCode refactoring to convert GPS coordinates into DMS format into an array
The user can enter GPS coordinates in two ways, Decimal Degrees or Degrees, Minutes, Seconds: ┌─────────────────────────────────┬─────────────────────┐ │ DMS (Degrees, Minutes, Seconds) │ DD…
-
14
votes1
answer441
viewsWhat is the purpose of Array and String Dereferencing implemented in PHP 5.5?
In the PHP manual, we can see New Features the functionality of Array and String literal Dereferencing. Example: echo 'string'[2]; // r echo ['stack', 'overflow'][1]; //overflow Thinking in case you…
-
14
votes3
answers1609
viewsWhat is the function of the vector (array)?
I’m studying algorithms with Portugol and I’m having difficulty understanding the function of the vector in the code. I already know how to use this structure.
-
14
votes2
answers2384
viewschar[] or *char malloc?
What difference in C between char text[10] or char *char = (char *)malloc(10*sizeof(char)); What advantage of using malloc on a pointer?…
-
14
votes1
answer1573
viewsWhy do the arrays index and other sequences start at zero?
Why the array does not start with 1? There is some technical reason to have adopted 0?
c array characteristic-language mathematics computer-scienceasked 7 years, 9 months ago Maniero 444,682 -
14
votes3
answers2102
viewsWhat is the difference between function and array assignment?
I have recently been coding in my projects where I need to add items in an array, so I don’t know if I should use native language functions for this, for example: array_push($meu_array, 50); or if I…
-
13
votes2
answers1894
viewsHow to align strings to use in a listview?
In my Android project I need to create a table with a listview but the data always comes misaligned. I place each record of my database in a position of a string array to use it in listview. The…
-
13
votes3
answers2493
viewsHow to choose the highest value of an array?
I’m trying to use the function max, but I can’t hit. // variáveis da diferença salarial $saldev[0] = $_POST ["Tdate5"]; $saldev[1] = $_POST ["Tdate9"]; $saldev[2] = $_POST ["Tdate13"]; $saldev[3] =…
-
13
votes2
answers864
viewsDifferences between Jagged Array and Multidimensional Array in c#?
There is difference in these arrays in c#? int[][][] int[,,] As far as I can see, it’s the same thing, but c# can’t cast from one to the other.
-
13
votes1
answer333
viewsWhy are arrays covariant and generic are invariant?
Arrays in Java are covariant, that is, it’s perfectly cool to do something like: Number[] meuArray = new Integer[10]; Generic types are invariant. The line below does not compile: List<Number>…
-
13
votes3
answers1684
viewsWhy Arrays start at 0 and not 1
Why arrays start at 0 and not 1 ? There is no 0 people, 0 animals, 0 nothing...(do not cling to this part) What is the point of doing this? I believe that it should not be just me who does not…
-
12
votes6
answers12772
viewsHow to locate a value in an array with a specific structure
I need to locate the position of one array within another, in the following structure: array{ [0]=>{ ["id"]=>"5744" ["fk"]=>"7" ["nome"]=>"Nivel 1" ["created"]=>"2014-04-30 16:54:14"…
-
12
votes7
answers552
viewsWhat is the difference between these parameters (array) in these methods?
I see it a lot in methods class Exemplo { public function exemplo1(array $parameters = array()) { } public function exemplo2(array $parameters) { } public function exemplo3($parameters = array()) {…
-
12
votes7
answers1017
viewsIs there any way to know if an array is associative or sequential?
In PHP, a array can be both associative as it can be a list, with sequential numbers. Is there any way to detect this difference in PHP? Example: $a = array('item 1', 'dois' => 'item 2'); //…
-
12
votes4
answers1090
viewsHow to create an array filled with values from 0 to n in javascript?
I need to create an array that is filled with the values of 0 a n, as if using the function range(n), Python3, but using Javascript features. I thought I’d create a function: function…
-
12
votes3
answers5507
viewsCount how many elements are duplicated in a string
The purpose is to account for the number of elements that are repeated in a string and not just check for duplicates or count how many times these elements appear. For example: "aabbca1m" // 2 (a,b)…
-
11
votes2
answers4531
viewsGroup and add array with PHP
I need to know how to group and add one array, but I’m not finding out how to do. $array = array("vermelho", "vermelho", "vermelho", "verde", "azul", "azul"); wanted a comeback like this 3 1 2 That…
-
11
votes3
answers1814
viewsSort a multidimensional array with numerical values
Suppose the following situation in which I have a array composed of several array numerically valued: $array = array( array(22, 25, 28), array(22), array(22, 23) ) I’d like to leave this array…
php array algorithm multidimensional-array classificationasked 10 years, 9 months ago Douglas Cabral 345 -
11
votes2
answers536
viewsWhy invert the array index in a for, to popular the array, makes the process faster?
I was doing some tests in Java and I noticed a very strange behavior. I made an array with two dimensions and populated the array in two different ways, filling with random numbers up to 2 31-1 and…
-
11
votes2
answers277
viewsHow do I use the jsondiffpatch library?
I’m having doubts about how to manipulate the data with the library jsondiffpatch The array original: [ {"id":1004,"idproduto":3,"forma":"Alface","preco":1,"quantidade":1},…
-
11
votes2
answers462
viewsHow to allocate dynamically when I don’t know how many positions I will use in C?
In a part of the code I need to transform an integer into binary and store it in a character array, however, I don’t know which integer I will receive to transform into binary, so I don’t know how…
-
11
votes3
answers2425
viewsWhy in Java is the size of an array an attribute and a String and a method?
In Java, the size of a array of any object can be obtained with length, which would be an attribute. But in the case of String is length(), a method. However, if you have a array of String, uses…
-
11
votes2
answers327
viewsIn PHP, does an array’s internal pointer make up its value?
Let us consider the following array: $a = [1, 2, 3, 4, 5]; As we make $b = $a we create a copy of array, so much so that changes made to one of the arrays will not affect the other. However, I…
-
10
votes5
answers74116
viewsRemoving a specific element in an array
I have the following array $input = array("item 1", "item 2"); But as it is dynamic, items can change $input = array("item 2", "item 4"); $input = array("item 4"); It is possible to use the…
-
10
votes1
answer1444
viewsWhat is an Array-Like?
A given string is an array-like, whereas a given number is not. Its respective objects are array-Likes (the objects themselves), right? A declared object, a DOM object is also an arraylike, correct?…
-
10
votes5
answers6566
viewsRemove last comma from an array
In this Code below I have a array that returns a comma to me at the end exe: '98602','98603','98604', How can I remove this comma? if (isset($_POST['checkbox'])) { foreach ($_POST['checkbox'] as…
-
10
votes4
answers5008
viewsOdd or even array in PHP
I need to create a array and tell if the values within it are even or odd. I made the code that way: <?php $par_ou_impar = array(2,3,4,56,5,42,98,100); for ($i = 0; $i < count($par_ou_impar);…