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
-
7
votes1
answer216
viewsUndefined error using replace()
I’m trying to make a sort of a people appointment, I made an attempt, but I was unsuccessful. Where is the error?? var nome =["Ana", "João", "Maria", "José"]; var frase = "@[1] é casado com @[0], e…
-
7
votes3
answers6440
viewsHow to check if an item is contained in an array?
What am I doing wrong in this if? if (angular.uppercase(nome[id]) in ['A', 'E','I', 'O', 'U']) { .... } If I only do so it works. But I will have to repeat to others. if (angular.uppercase(nome[id])…
-
7
votes2
answers2040
viewsHow to store the value of the indexes of this JSON in variable?
I have a function in php that returns it to me. [{"id":81,"username":"usuarioteste23"}] How can I save in a variable this ID and in another variable this Username? Thank you.…
-
7
votes2
answers318
viewsSeparate values from each array
Good morning, everybody, all right? I have the code that prints the different values found in 2 arrays and these values are saved in the different variable ($different) I need to know how to print…
-
7
votes3
answers161
viewsAre objects similar to arrays?
Objects are arrays in Javasscript? I have difficulty understanding how this is possible: var obj = { title: 'some value' } console.log(obj['title']); // some value In my conception the use of square…
-
7
votes5
answers34006
viewsHow to return the last record of an array with Javascript or jQuery?
I’m making a custom search filter where the user can select the brand and product features and I return their id. But I wanted to return only the last record of mine arrays where they contain all…
-
7
votes1
answer638
viewsRecovering list values from python lists
I have tried several things and I still can not grasp what the problem of my code, is a simple code. With numpy i place txt values in the array of arrays and want to make some copies to two other…
-
7
votes1
answer3557
viewsIs there a difference when merging two arrays with array_merge or with "+"?
I used to unite two arrays, in PHP, using the function array_merge: $arr3 = array_merge($arr1, $arr2); However, more recently I have seen unions of arrays with + (plus sign): $arr3 = $arr1 + $arr2;…
-
7
votes5
answers7032
viewsHow to return the sum of numbers of an array with indices of value greater than or equal to 2
I have the following array: array[0,2,0,0]; I need to create a function that only adds indexes with a value greater than or equal to two, as I should proceed? In this example you must return me 2;…
-
7
votes1
answer131
viewsHow to dynamically insert into an Std::array?
I’m migrating from C to C++ language, and I want to stop using traditional C language means, like the C vector. It is possible using the std::array insert elements dynamically as in std::vector?…
-
7
votes3
answers2700
viewsJS - Object array for array arrays
How do I convert an array of objects to an array of arrays in javascript? I did so, but returns an array of objects var items1 = new Array(); $.map(objResposta, function(value,index) { teste = new…
-
7
votes1
answer950
viewsVector within vector. What does it do in this context?
Forty students were asked the level of quality of food in the student canteen, on a scale from 0 to 10. ( 1 meaning horrific and 10 meaning excellent). Put the 40 responses into an entire array and…
-
7
votes2
answers225
viewsProblems with sizeof
I’m trying to get back the size of array, but it’s making a mistake. What to do? #include <stdio.h> char *palavra[] = {"casa", "carro"}; int main(){ int i; for(i = 0;i <…
-
7
votes2
answers362
viewsHow to pass an array as argument of a function per copy?
Like we know a array is used as a pointer in various situations. A parameter that waits for a array is actually a pointer, so what you copy is the memory address and not the data from array, is a…
-
7
votes4
answers2291
viewsHow to do a search inside this vector of objects?
How would I search for a record within my object? The program is a schedule of contacts, and I wanted him to do the search by the name I type in a Jpane and return the contact data searched. Here is…
-
7
votes1
answer566
viewsDynamic Memory Allocation X vector
I was studying this subject in C, and in most of the places I look for, one of the examples of using this resource is when you’re going to create a vector whose size you don’t know. Example: int…
-
7
votes3
answers69151
viewsVectors in Python
Okay, I’m coming from line C, and I’m having a hard time creating vectors in python. In C if I write vet = [5]; I would create a vector called vet with 5 indices. I wish I knew how to do this in…
-
7
votes2
answers91
viewsHow to shorten the process of creating an array without the need to write all indexes?
For example, if I need to create an array with 20 spaces, I need to always do so? $teste = array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,18,19); Or have some way to shorten that process, that 0 to…
-
7
votes1
answer83
viewsHow to use contents of an array to mount the name of a file to be saved?
I’ve tried to use colnames(), names() and nothing works. My data is something like that (however, I have 38,000 names and 38,000 columns): nomes <- c("nome105", "outro.nome_26", "qualquerCoisa")…
-
7
votes2
answers1249
viewsReturning function string directly and with array
What works: void *teste(); int main () { printf("\nRESULTADO: %s\n", teste()); return 0; } void *teste(){ return "Ponteiro"; } What goes wrong: void *teste(); int main () { printf("\nRESULTADO:…
-
7
votes2
answers70
viewsWhy does the return of the linear search for the element not found have to be -1?
Why should I return -1 at the end of a linear search if the element was not found? int linearSearch(int[] list, int size, int key){ for(int index=0; index<size; index++) if(list[index]==key)…
-
7
votes1
answer149
viewsWhat happens if a binary search does not find the element?
What happens if a binary search does not find the element? It goes into loop? What is the best way to finish the execution?
-
7
votes1
answer861
viewsFill char matrix with random words
I’m trying to develop an algorithm that can get an array of strings, sort by word size downwards, and put them into a char matrix by fitting all the words together if possible. The idea of…
-
7
votes6
answers1028
viewsHow to subtract an array
Assuming I have an array let arr1 = [ {nome: 'Fulano', idade: 19}, {nome: 'Ciclano',idade: 20}, {nome: 'João', idade: 20}, {nome: 'Maria', idade: 30}, {nome: 'Teste', idade: 52} ] and I have another…
-
7
votes1
answer827
viewsCopy a numpy.array without modifying the original
Given a numpy.array as the next: r = np.arange(36) r.resize(6, 6) Which results in: array([[ 0, 1, 2, 3, 4, 5], [ 6, 7, 8, 9, 10, 11], [12, 13, 14, 15, 16, 17], [18, 19, 20, 21, 22, 23], [24, 25,…
-
7
votes2
answers38101
viewsChecking if value exists in an array via search field
In pure javascript I can use indexOf(), something like that: var chaves = ['wmv','3gp','mp4','mp3','avi']; if(chaves.indexOf("avi") != -1) { alert("Ok!"); } But in the case of a search ground I’m…
-
7
votes2
answers1052
viewsWhat is the difference between foreach and map in Javascript?
const arr = [1, 2, 3, 4, 5] arr.forEach(i => i); arr.map(i => i); I’d like to understand the difference between the methods forEach and map in Javascript.…
-
7
votes2
answers99
viewsJavascript . NET Zip() method
I was reading that question and I noticed there’s no method Zip in Javascript, I would like to know how to implement a method that works the same way or if there is some other function that does the…
-
7
votes2
answers275
viewsDetermine how many "islands" a matrix contains
I need to create a program that receives as input a matrix size (up to 300 by 300) and the matrix values that will be stored (can be only 1 or 0). I must determine the number of "islands" (clusters…
-
7
votes1
answer121
viewsWhat is the "slicing phenomenon" when trying to read data from a heterogeneous array?
I was curiously reading a reply on how to store heterogeneous types in an array when I come across the following response snippet: You will have to store in each element of the vector the object and…
-
7
votes2
answers595
views"Operator" square brackets [] when creating the arrangement in C
Whenever I look for what the operator clasps [] makes, even in the tables that show all operators in C, appears that it serves to access an element of an arrangement. However, it is not always that…
-
7
votes1
answer177
viewsCreate a program that draws 6 numbers and shows how many times it was drawn
I’m making a program that draws 6 numbers (1 to 6) 1 million times and in the end shows how many times was drawn, but I have a doubt in the code, I’m optimizing in vectors not to use if, but in the…
-
7
votes2
answers347
viewsDoubt about the use of the Join method
I’m doing a Javascript course and I came up with a question in one of the exercises. Below is the exercise: Given the following object array: var usuarios = [ { nome: 'Diego', habilidades:…
-
6
votes2
answers7182
viewsHow to send an Array via POST to a PHP controller
I need to pass an array via POST to my PHP controller, the only way I have in mind is not to pass an array, but to pass the information through a separator (, |), but I didn’t want to keep giving it…
-
6
votes2
answers11874
viewsHow to create an infinite array?
I’m having a little problem and need to somehow create an infinite array, or rather, undefined, the user can enter as much data as necessary... How could I do it? I’m using the JDK6.
-
6
votes2
answers1552
viewsIs it possible to implement a dynamic array within a C structure?
How is it possible to create a dynamic array within a structure Example typedef struct historico_de_fabrica { Hist_id_rolos rolos[1000]; //<- este array em vez de ter 1000 posições queria em…
-
6
votes3
answers1650
viewsHow to turn a query into a json?
I’m trying to transform the data returned from a database query into Json format, so far it’s almost right, but I think the format is being created incorrectly! Json is being generated as follows!…
-
6
votes1
answer7135
viewsHow to call the Arrays.Sort (array, new methodoOrd()) method in Java?
Knowing that I have a class with an array of objects and another class that implements the interface Comparator. I would like any example just so I can learn and sort an array of objects by their…
-
6
votes2
answers1551
viewsSort words with accents in PHP
I am trying to alphabetically sort an array in PHP, where the key of each array position is a word. I’m using the function ksort. Sorting works, the problem is that accented words such as "acid" are…
-
6
votes2
answers12692
viewsFind out if item is in array
How do I check if an item is in a array? Ex: var Tabela : Array of String; begin Tabela[0] := 'Valor'; Tabela[1] := 'Value'; if Tabela[0] = 'Valor' then // do wathever; That would be the normal way,…
-
6
votes1
answer1411
viewsHow to place variables within vectors?
How do I create variables within a vector? Something like: int arr[] = {int x=1, int y = 2};
-
6
votes2
answers286
viewsReturn with all foreach lines
I have the following script: <?php $recursos_data = array( array( "id" => "0", "recurso_nome" => "madeira", "producao" => "%produz%", "estoque" => "200" ), array( "id" => "1",…
-
6
votes3
answers13619
viewsHow to split a string into an array in Javascript?
There is an elegant way to split a string into an array based on the example: var x = "FAT* FAT32*"; And result in something like this: x[0] = "FAT*"; x[1] = "FAT32*";…
-
6
votes2
answers433
viewsWhat is the difference between the union of an array via soma operator and the array_merge function?
To join two arrays in a new array in PHP, we can do through the function array_merge or through the sum operator (+). In this case we have two examples: $a = ['stack' => 'overflow']; $b =…
-
6
votes3
answers301
viewsWhat is the advantage of using include de array vs configuration file?
I have observed some codes where the programmer does the following: /** Arquivo A.php */ return array('databaseName' => 'bancoTeste', 'port' => 5208); /** Arquivo B.php */ $configs =…
-
6
votes1
answer139
viewsHow to convert a Javascript array to a PHP array?
The system gives me a Javascript matrix to work on the page. I can get this array with PHP, but I don’t know how to convert Javascript to PHP and work using PHP. This is an example of the Javascript…
-
6
votes3
answers436
viewsWhy is array_shift considered a slow function?
According to the Manual, array_shift removes the first element of the array. I have seen many criticisms on the Internet about the performance of this function, because it reorder the whole index of…
-
6
votes3
answers12748
viewsGenerate random numbers in an Array from 10 to 50
Since I can generate an array of random numbers with a limit, they should be numbers from 10 to 50. To generate random numbers from 0 to 50 I use: Random random = new Random(); int array[] = new…
-
6
votes3
answers5927
viewsGroup values from an array in PHP
I have a grid form that returns the following values within an Array: array (size=3) 0 => array (size=5) 'pei_seq' => int 0 'prg_cod_barra' => string '7899619704729' (length=13)…
-
6
votes1
answer180
viewsSelect database record for variable
The code below aims to select a database record and save it in a variable for later use of the data: #!/bin/bash dbName='basedados' dbUser='utilizador' dbPass='password' row=$(echo "select file_id,…