Questions tagged [arrays]

An array is a well-organized linear data structure composed of various elements (values, variables, or references). Each element is uniquely identified by one or more indexes. For addressing specific types of arrays, consider using these alternative tags: [vector], [arraylist], [matrix]. Additionally, when dealing with programming language-specific queries, make sure to tag the question accordingly.

"I am encountering an issue where I am using React and Express to retrieve data from a database, and although I am able to return an array of

I am working on a React app that communicates with an API using Express. Currently, I am using the GET method to fetch data from a database, and my fetching code looks like this: const posts = []; fetch(URL) .then(response => response.json()) .then(jso ...

Deciphering JSON data containing a nested array in Swift 3

I came across this question discussing JSON parsing in Swift 3 and found it quite informative. However, I encountered a JSON structure with an array for the "weather" key (highlighted by the red arrow). While I was able to successfully parse other parts of ...

What is the best way to generate an array from JSON data while ensuring that the values are not duplicated?

Upon receiving a JSON response from an API, the structure appears as follows: { "status": "success", "response": [ { "id": 1, "name": "SEA BUSES", "image": null }, { "id": 2, ...

Problematic PHP/AJAX: How come my getAttribute function is only selecting the initial line within the foreach loop?

My goal here is to display a list of users, each with a button that sends unique IDs to the database. The issue I'm facing is that the code only works for the first user in the list and not the rest. I suspect this is because every list item has the s ...

Error: While constructing my React application, a TypeError occurs as it is unable to retrieve the property '0' of an undefined value

While trying to deploy my react application, I encountered the following error message: Error: Unable to read property '0' of undefined Oddly enough, this error only appears during the building process of the app, not when it's running on port 3000. Can ...

Obtain the index for a data point using a SciPy sparse array

Currently, I am working on a CSR sparse array where there are many empty elements or cells. This array needs to support both forward and backward indexing. In other words, I should be able to provide two indices and receive the corresponding element (e.g., ...

Utilize Material UI to iterate through an array using a map function

Is there a specific way to handle mapping over objects from an axios call when using a Material UI table? const tableRows = this.props.reduxState.map(row => { const {item_description, purchase_date, item_price, item_link} ={TableRowColumn} ...

Exploring the automated retrieval of data from arrays in Java objects: A comprehensive guide

My goal is to automatically create Java objects from JSON data obtained from a REST API. The JSON array contains properties of different shops, and I aim to generate one object per shop with all its respective properties. The following code helped me achi ...

Ways to retrieve an array saved in another JavaScript document

I am in the process of developing my own lorem ipsum application and keen on maintaining clean code by storing my word bank in separate files. How can I retrieve an array stored in a different JavaScript file? Rather than manually inputting harry = ["", "" ...

When you try to remove an element from an array by its index in Vue JS, the outcome may not be

Here is an array that I have: var hdr = ("name", "date", "start_time", "selling_item", "total_call", "end_time", "ad_num", "area", "order_num"); //this data comes from the database Now, I need to rename these array elements according to prope ...

Determine the instance's name as a string in JavaScript

Currently, I am utilizing Three.js in combination with javascript. Upon running the following line of code: console.log(this.scene.children[1]) I receive the following output in the console within Chrome: https://i.stack.imgur.com/6LBPR.png Is there a w ...

Troubleshooting Issues with Retrieving Android Data from MySQL Database using PHP and JSON

Even though I have encountered this question multiple times on stack overflow, I have tried all the solutions provided and none of them seem to work for me. I am attempting to display data in a List View. The data is stored in JSON format and it appears t ...

Error message: ngRepeat does not allow duplicate elements in an array

Upon review, I discovered this particular piece of code: <!DOCTYPE html> <html> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script> <body> <script> var app = angular.module("myS ...

Tips for sorting through an array by odd or even index values

Is there a way to filter out array entries based on odd or even index numbers? Array ( [0] => string1 [1] => string2 [2] => string3 [3] => string4 ) I am looking to remove the entries with indexes [0] and [2]. For example, if I ...

Error occurs when attempting to read the 'map' properties of null because the JSON array is double nested

Within my code, I am attempting to access the URLs of two thumbnails in the JSON data below. Currently, I can only retrieve the information from the first array: <>{post.attributes.description}</> However, I am encountering difficulty retrievi ...

Understanding Arrays in Angular JSIn this article, we

I am new to working with Angular JS. Currently, I am populating an array and attempting to showcase its contents on the HTML page using ng-repeat. $scope.groupedMedia = []; // Elements are being added through a for loop. $scope.groupedMedia[year].push(r ...

Traverse a collection of nested objects containing arrays as their values

Consider the following object: { "apples": [ "one", "two" ], "oranges": [ "three", "four" ] } If I want to find the value four within this object, how can I do so efficiently? Would a loop work, like the one shown below? for (var ...

Styling Javascript Objects

[ [ {"path":"path2","value":"kkk"}, {"path":"path0","value":"uuu"}, {"path":"path1","value":"ppp"} ] ] The result obtained from my manipulation is shown above. However, I require the format to be as depicted below: ["path":"pat ...

Eliminating empty elements from arrays that are nested inside other arrays

I am facing a challenge with the array structure below: const obj = [ { "description": "PCS ", "children": [ null, { "name": "Son", ...

Exploring Numpy Arrays through Loops and Searches

Currently, I am looping through a numpy array and performing a search operation which is taking approximately 60 seconds to complete for arrays (npArray1 and npArray2 in the sample code) containing around 300,000 values. To elaborate, I am seeking the ind ...

Error encountered in Ionic app: array.push() is not a valid function

A situation arose in my application where I have a controller and factory set up. Inside the factory, there is an array that should hold IDs of certain elements. However, when attempting to push an element into the array, an error is triggered stating: ...

Why is it impossible for me to delete the class / property of this object?

Within a series of nested divs, there are additional divs containing multiple imgs. The goal is to cycle through these images using CSS transitions. To achieve this, a JavaScript object was created to track the divs, sub-divs, and images. Three arrays were ...

Is it possible to bypass the initial bracket when working with arrays in PHP?

I am trying to display the [number] value from each array, but with different parent brackets [], how can I skip the first one and retrieve the desired [number]? Basically, I need to ignore the first set of brackets [] and access the second one containing ...

Obtain the result of two "Synchronous" nested queries using Express and Mongoose

I need to fetch an array of elements structured like this: ApiResponse = [ {_id: 1, name: Mike, transactions: 5}, {_id: 2, name: Jhon, Transactions: 10} ] The user data is retrieved from a query on the "Users" schema, while the tr ...

What is the best way to monitor changes in objects within a JavaScript array?

Currently, I am in the process of developing a Todo application using electron and Vue.js. In my project, there is an array of objects called items. Each object follows this format: {id: <Number>, item: <String>, complete: <Boolean>, ...

What is the best way to iterate over an array of objects?

I have an Array of Objects that I need to use in order to create an HTML Table: Array(5) 0: Object id: 4 name: Sand Jane address: Green Sand Street ... ... ... 1: Object 2: Object ... ... ... Currently, I am able to perform a search wit ...

Issue encountered when attempting to push jQuery AJAX requests into an array

I'm attempting to store ajax requests in an array called deferreds. However, I'm consistently encountering the error message below: Uncaught SyntaxError: missing ) after argument list As a reference, I've been using this guide: Pass in an array of Deferr ...

Utilizing Linux commands to extract information from log files and store it in an array

I found a log file with the following content 2018/01/14 12:27:27|get_offers|ok|1678537191|64.233.173.132|info=wifi 2018/01/14 12:27:27|get_offers|ok|1678537191|64.233.173.132|info=wifi 2018/01/14 12:27:27|get_offers|ok|1678537191|64.233.173.132|info=wifi ...

Importing a newly harvested array from a .js file (array that has been exported)

I followed this procedure with assistance from T.J to resolve my issue To address the problem, I made changes to my process. The steps I took are as follows: I switched from exporting an array through a JS file to saving a JSON file instead. Using the .g ...

What is the best way to trim a string property of an object within an array?

I am seeking a solution to access the "description" property of objects within an array and utilize a string cutting method, such as slice, in order to return an array of modified objects. I have attempted using for loops but have been unsuccessful. Here ...

Converting POST data into an array using Angular

I am facing an issue with my post request setup in a NodeJS app. The data sent returns as an array, but I am struggling to convert it into the desired format. My Angular code is structured as follows: newWord = ''; keyword = ''; onCli ...

What is the best way to input a dynamic post array in PHP?

Explaining this might be challenging, but I will do my best. I have multiple input posts with custom conditions, which means there can be as many custom conditions as needed. Here is the HTML: <input name="type[]" value="type 1"> <input nam ...

Find the difference between array_A and the documents in array_B using MongoDB's $match operator, and return the result as Array_C

I need to create an array_C that includes only the elements from array_A that are not present in array_B. My approach involves using $match in aggregate to specify array_B. For instance: array_A = [1, 2, 3] array_B = [2, 4, 6, 8, 10] array_C = [1, 3] I a ...

The outcome of my function designed to calculate the highest possible profit using k transactions is a null array

I have developed a custom function to calculate the maximum profit from a series of stock transactions given a specific number of transactions allowed. Each transaction involves buying at a low price and selling at a higher price, with the rule that you ...

What is the best way to divide an array while extracting data from a JSON object using

Currently, I am parsing the json data. My goal is to find a specific property within the json object that contains two nested arrays (list and array). However, when extracting the values, they are all being stored in a single array. Is there a way to separ ...

Calculate the sum of elements in an array based on a condition provided in a different

Looking for help with summing an array based on conditions in another array using Python. sum=0 for i in range(grp_num): if lower_bounds[i] > 0: sum = sum + histo1[i] I was thinking the numpy equivalent would be np.where(lower_bounds>0, ...

Discovering collections of vectors that add up to zero

I am working with four arrays, each containing 3 arrays. For example: set1 = [array([1, 0, 0]), array([-1, 0, 0]), array([0, 1, 0]), ...] My goal is to determine the number of combinations of vectors that sum to zero. The current solution involves nested ...

The sort function in Reactjs does not trigger a re-render of the cards

After fetching data from a random profile API, I am trying to implement a feature where I can sort my profile cards by either age or last name with just a click of a button. Although I managed to get a sorted array displayed in the console log using the h ...

delete specific elements from an associative array

I am working with two arrays: $pool = array( 'foo' => array('foobar1'), 'bar' => array('foobar2'), 'lou' => array('foobar3'), 'zuu' => array('foobar4') ); $remove = array('lou', 'zuu'); What is the best way to create thi ...

Explore the properties within an array of objects through iteration

Here is the array I'm working with: const myArray = [{ id: 1, isSet: true }, { id: 2, isSet: false }, ...]; I only need to iterate over the isSet properties of the objects, ignoring all other properties. Initially, I attempted the following solution: le ...

Converting php array submitted from a form using ajax

I have a form on my website that collects user input and sends it to an email address using php. The form includes a checkbox input where users can select multiple options, which are then stored in an array. However, when the form is submitted, the email r ...

Guide to subtracting elements within a list

I have created a function that takes in a list of numbers such as [0.5, -0.5, 1] and then outputs a new list with each index containing the sum of the differences between the current value and all other values. For example, if the input is [0.5, -0.5, 1], ...

Is there a PHP library function that can combine multiple arrays with nested layers into a single array using a specific

I have two arrays that I want to merge based on the "client_id" key (preferably using a PHP function): [all_client] => Array ( [0] => Array ( [client_id] => 1 [client_name ...

Matter of Representing Nested For Loops in Javascript Arrays

When I have two arrays that intersect at certain elements, the resulting function should ideally output A, B, Y. However, in this case, it displays all possible combinations of lista.length * listb.length. <script> window.onload = function(){ ...

Decipher the JSON code to modify the data

I have a JSON array below. {"entries":[{"uid":155551338258538,"photo":"https:\/\/m.ak.fbcdn.net\/profile.ak\/hprofile-ak-prn1\/323887_155551338258538_1152153357_q.jpg","type":"user","text":"shikhadamodar","path":"\/shikha.dam ...

Utilize Array.push to add 2 new rows to a table using Angular 4

I have two arrays that are almost identical, except for two items which are the fakeDates: this.prodotti.push({ idAgreement: this.idAgreement,landingStatus: this.landingStatus, landingType: this.landingType, startDate: this.startDate, expirationDate: thi ...

Enabling communication between JavaScript and PHP and vice versa

I am currently working on developing a Firefox plug-in with the purpose of gathering all the domains from the links located on the current site and showcasing their respective IP addresses. In order to achieve this, I have written JavaScript code that incl ...

Is there a way to make jQuery Fancybox recognize my object as a valid parameter for opening?

I'm dealing with some HTML code that looks like this: <div id="logos" class="downloadlist"> <ul> <li><a href="/toolkit/logos/download.jpg" data-image="images/toolkit/logos/one.jpg">First Logo</a></li> ...

How to retrieve a random element from an array within a for loop using Angular 2

I'm in the process of developing a soundboard that will play a random sound each time a button is clicked. To achieve this, I have created an array within a for loop to extract the links to mp3 files (filename), and when a user clicks the button, the filen ...

What is the best way to show nested labels on separate lines simultaneously?

Despite attempting to utilize the map method as suggested in my research, it appears that it may not be suitable for the structure I am working with: const stepLabels = [ { labels1: ['First One'] }, { labels2: ['Second One', 'second One'] }, { labels ...

retrieve PHP function calls as an array using Ajax

While working in PHP, I have encountered a situation where I needed to call a PHP function using AJAX: <button onclick="loop()">Do It</button> function loop() { $.get("ajax.php", { action: "true" }, function(result) { $("in ...

Collection of arrays (Python/NumPy)

Working with Python and NumPy, I currently have two arrays that look like this: array1 = [1 2 3] array2 = [4 5 6] My goal is to create a new array: array3 = [[1 2 3], [4 5 6]] and add elements to it. For instance, if the new items to append are: array ...

Problem with sorting when using $in operator in MongoDB

I am looking to retrieve documents from a MongoDB collection where the IDs match those in an array: [ '5f80a44d0179262f7c2e6a42', '5f8c00762fae890e9c4d029c', '5f802cf8abac1116a46bf9d4' ] The problem arises when the documents are not returned in the ...

Why isn't my API's JSON Response showing up in PHP?

Having trouble displaying the JSON response from an API call in PHP. Despite confirming that the server, IP settings, and API status are all fine on the provider's end, I am unable to identify the problem. This is how I'm handling the PHP part: PHP $u ...

Extract data from a JSON-encoded array using JavaScript

I sent a JSON encoded array to JavaScript. Now I want to access that array to retrieve the different elements. When I print it out using console.log(), I see this array: array(1) { [16]=> array(2) { [3488]=> array(1) { [0]=> ...

Looking to query JSON using jQuery - how can I accomplish this?

Currently, I am utilizing session storage to temporarily store data and attempting to search for a specific string (CatalogNumber) within the session data. If the string is not found, my goal is to add it. Despite my efforts, I have encountered issues wit ...

Using Vue's v-for directive: Populate HTML dynamically with an event handler (@change) from an array within a component template

This is the setup I am currently using: HTML <question v-for="question in questions" v-bind:id="question.id" v-bind:title="question.title" v-bind:statement="question.statement" v-bind:interaction="question.interaction" @onchange-vg=" ...

Converting an array into a string, transitioning from PHP to JavaScript

Hey everyone, I'm currently working on passing an array to a JavaScript file and encountering this error: An exception has been thrown during the rendering of a template ("Notice: Array to string conversion"). What I need is: data: ['2017/7','2017/8'] ...

Encountering difficulty in retrieving data from an unidentified JSON array using Javascript

Exploring the realm of Javascript and JSON, I find myself faced with a challenge - accessing values in an unnamed JSON array. Unfortunately, as this is not my JSON file, renaming the array is out of the question. Here's a snippet of the JSON Code: [ { ...

shifting the length of o to the right by zero with the

While exploring the polyfill function for Array.includes, I stumbled upon the following lines of code: // 2. Let len be ? ToLength(? Get(O, "length")). var len = o.length >>> 0; // 4. Let n be ? ToInteger(fromIndex). // (If fromIndex is undef ...

Guide to swapping out the variables "labels" in JavaScript

Here is the object structure: { 'File_12345.ZLM': { MeterID_12345: { BASIC_INFO: [Object] } } } { 'File_678910.ZLM': { MeterID_678910: { BASIC_INFO: [Object], } } } ============================================ ...

What is the best way to incorporate custom data into react-table?

After following the example at while using react-table, everything worked as expected. However, when attempting to use my own data, I encountered an issue where I kept receiving a TypeError stating that 'data is undefined' in useTable. Even though my arra ...

Utilizing PHP to iterate over a JSON array and generate HTML content

I am utilizing bootstrap datatables to present data retrieved from an API in a tabular format. Below is the sample data: { "response_status": { "status_code": 0, "status_message": [ { "reg_number": "123", "company": "Compan ...

Transforming a for loop into a sliced operation on a NumPy array

I am working on a loop to calculate the elements of a 3D numpy array. The code looks like this: A = np.zeros((N - 2, N - 2, N - 2)) for i in range(1, N - 1): for j in range(1, N - 1): for k in range(1, N - 1): A[i - 1, j - 1, k - 1] ...

What is the process of creating a new array by grouping data from an existing array based on their respective IDs?

Here is the initial array object that I have: const data = [ { "order_id":"ORDCUTHIUJ", "branch_code":"MVPA", "total_amt":199500, "product_details":[ { ...

The concept of using the `map` method within a

Hi there, I could use some assistance with a tricky issue I'm facing. My current task involves rendering a cart object that includes product names, prices, and quantities. Each product can have its own set of product options stored as an array of ob ...

if condition inside the echo statement nested inside a foreach loop

Currently, I am attempting to dynamically set the selected attribute on an <option> element based on an array. Although I am very close to achieving my goal, I have not quite reached it yet... $departments = array("Finance", "IT", "Retail",); forea ...

Remove objects from an array if they share identical key values

I'm having trouble getting this to work. I have an array of objects that looks like this: let myCities = [ { value: 'Barcelona', code: 02342837492482347 }, { value: 'Rome', code: 28282716171819 }, { value: 'Barcelona', co ...

Is there a more efficient alternative to `[].push.apply(this, arr)` for combining elements in an array instance within a constructor?

It only takes 0.15ms for this line in my constructor function to execute. [].push.apply(this, selector); I'm not satisfied with the 0.15ms execution time. I believe there must be a quicker alternative available. This particular line seems to be conv ...

What is the best way to utilize the forEach method in React to manipulate a navigation element containing multiple links?

Here is the code I'm trying to convert: document.addEventListener("scroll", function() { const links = document.querySelectorAll(".nav-link"); for (const l of links) l.classList.toggle('scrolling', window.scrollY &g ...

Trying to add a single value to a specific index in a JavaScript array, but it is mistakenly assigning multiple values at once

Currently tackling a matrix algorithm with an early roadblock. The array at hand is: [ [ 0, 0, 0 ], [ 0, 0, 0 ], [ 0, 0, 0 ] ] The goal is to convert it into this: [ [ 0, 0, 0 ], [ 0, 9, 0 ], [ 0, 0, 0 ] ] My plan was to alter the middle value like so ...

Code for dividing large JSON data based on node names in a generic way

I am facing a challenge with handling very large JSON files, where the car array can contain up to 100,000,000 records. The file size ranges from 500mb to 10 GB and I am currently using Newtonsoft json.net for processing. Input { "name": "John", "age": " ...

Issue with the _.filter function in lodash library when used in a Node.js environment

My goal is to remove rows from a CSV file that already contain email addresses found in Mailchimp. Although I attempted to achieve this with a function, it seems that the number of elements returned is not accurate: async function testDeleteEmails(listID, ...

Extracting Nested Numpy Arrays

I am dealing with a pandas Series that contains one numpy array per entry, all of the same length. My goal is to convert this into a 2D numpy array. Despite knowing that Series and DataFrames don't handle containers well, when using np.histogram(.,.)[0] on ...

Submitting JSON data using Alamofire in Swift

How do I send an array of JSON objects using Alamofire in Swift? The data I need to post is as follows: dataArray = [{ "time": 1, "score": 20, "status": true, "answer": 456 }, { "time": 0, "score": ...