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.

Troubleshooting JSON Array Index Problems

I'm having trouble reaching index 3 in the array using the javascript options on my webpage. The final question "are you satisfied with your choice?" is not showing up for me. I'm not sure what I might be missing or doing incorrectly in this situation. L ...

Filtering an array dynamically in Typescript depending on the entered value

My task involves filtering arrays of objects based on input field values. Data data: [{ taskname: 'Test1', taskId: '1', status: 'Submitted' }, { taskname: 'Test2', taskId: '2', status: 'Re ...

Encountered issue while converting half of the string array to JSON using JavaScript

I encountered an issue with the code below while trying to convert an array into JSON. Here is my code: <html> <head> </head> <body style="text-align:center;" id="body"> <p id="GFG_UP1" style="font-size: 16px;"> </p ...

What is the best way to access data from outside a forEach loop in JavaScript?

I am trying to access the value of my uid outside of the foreach loop in my code. Can anyone assist me with this? This is the code I am working with: var conf_url = "https://192.168.236.33/confbridge_participants/conference_participants.json?cid=009000 ...

Attempted to identify whether an item exists in an array, and if it does, then add the item to the array; if not, then perform

Allow me to make some clarifications as it might be a bit confusing initially. This project I'm working on is for school. I don't expect anyone to do it for me, but I need help with a specific part. I'm creating a simple shopping cart using Vue.js. When a ...

Obtaining a series of coordinates from a Numpy array

I have a 100x100x100 numpy array that represents a 3D volume composed of 2D slices. My goal is to conduct cross correlation on the object in this volume across multiple volumes using a template derived from the volume with the best signal-to-noise ratio. ...

When using a function linked to an API request, an uncaught TypeError is thrown: Unable to access the 'includes' property of an undefined value

Utilizing the movie DB API (), I am displaying the results of my call on my page using Vue. The API supplies all the necessary data for me to achieve my objective, as demonstrated in this image https://i.stack.imgur.com/vP4I2.jpg Beneath each show's ...

converting the names of files in a specific directory to a JavaScript array

Currently working on a local HTML document and trying to navigate through a folder, gathering all the file names and storing them in a JavaScript array Let's say I have a folder named Videos with files like: - VideoA.mp4 - VideoB.mp4 How can I cre ...

Can anyone suggest a more efficient method for looping through this multi-dimensional array in PHP?

I am currently utilizing the Solr search engine, which provides my search results in a structured format: array(2) { ["responseHeader"]=> array(3) { ["status"]=> int(0) ["QTime"]=> int(1) ["params"]=> array(5) { ...

Export array data to a CSV file using Node.js

I am facing a challenge in writing an array to a CSV file using the node's fs module. Every time I attempt this, new columns are created due to the commas within the array elements. How can I ensure that the array remains contained within a single col ...

Expanding the size of an array list item in React

I have an array containing various currencies: const currencies =['USD','EUR','AUD','CNY','AED', 'AFN', 'ALL', 'AMD', 'ANG', 'AOA', 'ARS', 'A ...

Implementing an array of functions on an array of elements based on their positions

Imagine the scenario: def x_squared(x): result = x * x return result def twice_x(x): result = 2 * x return result def x_cubed(x): result = x * x * x return result x_values = np.array([1, 2, 3]) functions = np.array([x_squared, t ...

Having trouble looping through an array of objects containing images in Javascript?

I am currently facing challenges with iterating through an array of objects that contain images. The array appears empty when logged in the console, but upon inspecting it in the console, I can see all the objects along with their iteration numbers. I have ...

Filtering data in AngularJS by parsing JSON records

I have a JSON file containing restaurant information and I need to display the data by grouping them based on their respective address fields. For example, all restaurants with the address 'Delhi' should be shown first, followed by those from &ap ...

Make sure to consistently receive the distinct key notice: Every child within a set must possess a unique "key" property

Trying to understand the part of this code that suggests I don't have keys for the pushed array items: import { Accordion, AccordionSummary } from '@material-ui/core' import { createStyles, makeStyles, Theme } from '@material-ui ...

Is there a way in PHP to increase the quantity by 1 if the value is present in the array?

I want to update the quantity in the session cart or add a new item if it doesn't already exist. If the item is already in the cart, I am looking to increase the quantity by 1. if (!isset($_SESSION['cart'])) { $item = array('pid&ap ...

Tips for understanding nested JSON or array data structure?

My data is stored in a constant called translations and it looks like this: { "item-0": { "_quote-translation": "translation Data", "_quote-translation-language": "English", "_quote-trans ...

Merge arrays values with Object.assign function

I have a function that returns an object where the keys are strings and the values are arrays of strings: {"myType1": ["123"]} What I want to do is merge all the results it's returning. For example, if I have: {"myType1": ["123"]} {"myType2": ["45 ...

Tips on transforming values from a json array into a Java string

I am trying to extract values from a JSON array and present them on a page. Here is the code snippet that I have implemented. The getresponse class is responsible for sending an HTTP request to a PHP page, receiving the JSON array, and storing it in the p ...

Create a discord.js bot that can randomly select and send a picture from a collection of images stored on my computer

I'm currently working on a bot that sends random pictures from an array of images stored on my computer. However, I encountered an issue when trying to embed the image, resulting in the following error message: C:Users47920DesktopDiscord Bot ode_modul ...

Transforming a TypeScript enum into an array of objects

My enum is defined in this structure: export enum GoalProgressMeasurements { Percentage = 1, Numeric_Target = 2, Completed_Tasks = 3, Average_Milestone_Progress = 4, Not_Measured = 5 } However, I want to transform it into an object ar ...

Convert a multi-dimensional array into a "flat" structure while preserving array keys and values

I have a complex array structure with X number of dimensions. Here is an example of the array: Array ( [system] => Array ( [step_x_y] => Array ( [0] => Schnitt %1 von %2 [1] => Trin %1 af ...

Creating a new array in Vue.js by filtering the results of a promise iteration

Is there a way to use the splice method to insert promise values from an old array into a new one for vue reactivity? I'm encountering an issue where the newArray remains empty and does not receive any values. Check out this link for more information. & ...

Clear the default content from a Bootstrap modal form

Each object from the 'myData' array is being used to create divs. Additionally, there is a bootstrap modal with a form for adding an external object. Once this external object is added to the array 'myData', it will be displayed in the same format as descr ...

Searching for a specific value in various Json files: A guide

My goal is to create an application where users can input longitude and latitude coordinates of a location, and the application will return the associated grid code from one of three JSON data files. I am attempting to search through all three files simult ...

What is the best way to create a list using only distinct elements from an array?

If I have a collection of different colors: Red Blue Blue Green I aim to extract only the unique colors and store them in an array. Subsequently, I plan to incorporate each color from that array into an existing color list. The desired outcome would l ...

Rebuilding associative arrays using PHP

I'm attempting to reconstruct this array using a foreach loop : Array ( [0] => Array ( [ID] => 0 [NAME] => 400 [QUANTITY] => 12 ) [1] => Array ( [ID] => 0 ...

Exploring the Depths of React by Cycling Through Arrays in Tabular Format

One issue I'm facing is that I have an array named paymentMethods which I'd like to iterate through in tabs. However, I seem to be struggling with the iteration part. To take a closer look at my code, please visit my codesandbox HERE <div& ...

The Python function is functional when dealing with individual values, however, it is not compatible with vectors. The error message it throws is "only size-1 arrays can be converted to Python scalars

As a beginner in Python with some experience in Matlab, I am attempting to create a function for the Gaussian kernel with a mean of 0. Here is the code I have written: import numpy as np import math def GaussainKernel(x,sigma): xx = np.array(x) re ...

Tips for retrieving data values in Vue.js

data(){ return { filters: [ { key: 'a', value: '12' }, { key: 'b', value: '34' }, { key: 'c', value: '56' }, { key: 'd', value: '78' }, { key: 'e', value: '90' }, ], } } Is it possible to extract th ...

Is there a way to verify if the object's ID within an array matches?

I am looking to compare the ID of an object with all IDs of the objects in an array. There is a button that allows me to add a dish to the orders array. If the dish does not already exist in the array, it gets added. However, if the dish already exists, I ...

Assign a unique value to every line in a JSON string within the Vue.js hierarchy of components

I created a Vue component that initializes an empty list and an object like this: data: function(){ return { list: [], newThing: { body: '', }, }; }, The list is then populated with JSON data fetched ...

Creating multi-dimensional arrays using array lists with Axios and Vue.js

My knowledge of axios and JavaScript is limited, and I find myself struggling with creating a multi-dimensional array. 1. This is how I want my data to be structured : https://i.stack.imgur.com/kboNU.png userList: [ { ...

An array containing numerous "case" triggers

var message = "hello [[xxx]] bye [[ZZZ]]" var result, re = /\[\[(.*?)\]\]/g; while ((result = re.exec(message)) != null) { switch (result[1].toLowerCase()) { case "xxx": console.log("found xxx"); br ...

Condition in Bash script for verifying JSON response

This particular script is designed to notify me whenever there is an error response. Problem: Even when the execution is successful, I am still receiving an email. Bash script: #!/bin/bash DATA=$(wget --timeout 5 -O - -q -t 1 http://this.url/?parm=1&a ...

Create an array filled with multiple arrays containing objects

To achieve the desired array of array of objects structure, I need to populate the data like this: let dataObj = [ [ { content: "test1"}, { content: "test2"}, { content: "test3"} ], [ ...

What is the proper way to integrate a PHP variable containing an SQL query into an already existing SQL query using the $db->updatePhoneNumbers() method?

I'm currently developing a database for Users where each user can have multiple phone numbers. To accomplish this, I've implemented a JavaScript function in the form that generates new input fields and stores the information in a nested array. My approach ...

What is the correct way to extract results from an Array of Objects in Typescript after parsing a JSON string into a JSON object? I need help troubleshooting my code

Here is my code for extracting data from an array of objects after converting it from a JSON string to a JSON object. export class FourColumnResults { constructor(private column1: string, private column2: string, private column3: string, priv ...

What is the best way to add selected values from a multi-select dropdown into an array?

Attempting to populate an array from a multiple select dropdown, I've encountered an issue. Despite using splice to set the order of values being pushed into the array, they end up in a different order based on the selection in the dropdown. For insta ...

What is the best way to divide a single object in an array into multiple separate objects?

In my dataset, each object within the array has a fixedValue property that contains category and total values which are fixed. However, other keys such as "Col 2", "Col 3", etc. can have random values with arbitrary names like "FERFVCEEF erfe". My goal is ...

Effortlessly add and manipulate multiple classes in a generic class using querySelectorAll and classList, eliminating the

I'm encountering an issue that requires me to repeatedly utilize querySelectorAll with Element.classList. Each time, I must convert the NodeList obtained from Element.querySelectorAll into an Array. Then, I need to iterate over the Array using a forEach ...

Discovering common elements in various arrays of objects

Details: record1 = [{"site": "The Blue Tiger", "zipcode": "E1 6QE"}, {"site": "Cafe Deluxe", "zipcode": "E6 5FD"}] record2 = [{"site": "Blue Tiger", "zi ...

In JavaScript, combine two arrays of equal length to create a new array object value

Trying to figure out how to merge two arrays into a new object in JavaScript var array1 = ['apple', 'banana', 'orange']; var array2 = ['red', 'yellow', 'orange']; If array1[0] is 'apple&apos ...

When utilizing Javascript's Array.push method, a nested array is generated that is inaccessible using the index

I have reviewed several articles discussing the issue of asynchronous calls returning undefined. Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference Get data from fs.readFile However, none of these articles ...

Tips on extracting only abstract JSON data from an API response?

Description I'm attempting to send a request to an API using PHP cURL $access_token = $tokens['access_token']; $headers = array( "Authorization: Bearer " . $access_token ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,env('USER_INFO')); curl_seto ...

When evaluating objects or arrays of objects to determine modifications

How can we detect changes in table data when users add input to cells? For example, if a user clicks on a cell and adds an input, the function should return TRUE to indicate that there are changes. If the user just clicks on the cell without making any ch ...

Calculate the sum of values in a JSON array response

I recently received a JSON string as part of an API response, and it has the following structure: { "legend_size": 1, "data": { "series": [ "2013-05-01", "2013-05-02" ], "values": { "Sign Up": { "2013-05-05": 10, ...

Display a JSON encoded array using Jquery

Within an ajax call, I have a single json encoded array set: $var = json_encode($_SESSION['pictures']); The json encoded array is stored in a variable called "array" When I try to display the contents of "array" using alert, I get this respons ...

Steps to remove the smallest number from an array: if there are multiple smallest numbers, remove the first one

I am currently working on a script that takes an array of random numbers as input. I have successfully implemented code to remove the lowest number in the array, but I'm facing an issue when there are multiple occurrences of this number. How can I ens ...

What makes this effective in JavaScript?

While working on a project, I encountered the task of comparing coordinates in two arrays at the same index to see if they are identical. There are various methods to achieve this, but one particular approach piqued my interest. Why does it yield the expec ...

How can I generate a sorted array of objects in a JSON output using PowerShell?

Is it possible to generate a JSON output with an array of objects sorted in ascending order based on the "count" property? I need to maintain the original $result object structure, without caring about the order of "Good" or "Bad", My goal is to sort the o ...

Python Enum using an Array

I am interested in implementing an enum-based solution to retrieve an array associated with each enum item. For example, if I want to define a specific range for different types of targets, it might look like this: from enum import Enum class TargetRange ...

Counting elements in an array using PHP

I'm encountering an issue with my PHP code. It is supposed to push elements to an array within a loop and then count the elements at the end of that loop. However, for some reason, it's not displaying anything. Can anyone provide assistance? <?php ...

What is the best way to store a collection of class instances in a serialized format

Is there a way to convert an object that contains a list of objects into JSON format? Error message received: TypeError: Object of type person is not JSON serializable Here's the code snippet in question: import json class person: def __init__( ...

Using Vuex and array.findIndex but unable to locate a matching element

I am encountering an issue with the array.findIndex method. Despite being certain that there is a match in the array I am searching through, findIndex consistently returns -1. let index = state.bag.findIndex((it) => { it.id === item.id console. ...

"Transforming JSON data into a format compatible with Highcharts in PHP: A step-by-step

Currently facing an issue with converting the given array format into a Highcharts compatible JSON to create a line chart. Although everything else is functioning correctly, I am struggling with this specific conversion task. { name: [ 1000, ...

Tips for creating an array in a <script> tag within an hbs view template

Currently, I am delving into the world of full stack web development with a focus on Node/Express. The project at hand is to create a voting app as part of a challenge from FreeCodeCamp, which you can find here. To display user votes in pie charts on the f ...

Generate Numpy array without explicitly specifying elements

Using the following initial array: x = range(30,60,2)[::-1]; x = np.asarray(x); x array([58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30]) You need to create a new array similar to this: (Note that the first item repeats) However, if there is ...

Successful Mongoose query in Node.js, however the array remains empty even after using forEach loop. Issue with MongoDB integration

After performing a forEach inside an asynchronous method, I am trying to return an array of names. The issue is that despite the forEach working correctly, the array always ends up empty. On the website side, here is my request: function retrieveCharity( ...

Can you provide examples of iterating through multiple maps with key-value pairs using ng-repeat in AngularJS?

Within my controller, the data is structured like so: "type": [ { "aMap": {"5.0": 0}, "bMap": {"10.0": 0}, "cMap": {"15.0": 0}, "dMap": {"20.0": 0}, "desc": "CG" }, { "aMap": {"5.0": 0}, ...

Storing data with jQuery

Looking to store objects in jQuery for events. Each event will have a date, title, and some text that needs to be stored in an array. Wondering if using a multi-dimensional array would be the best way to go so I can easily iterate through them with a count ...

Creating one-of-a-kind combinations in PHP

Consider this associative array: $array = []; $array['Apple'] = 1; $array['Orange'] = 2; $array['Banana'] = 3; $array['Grape'] = 4; $array['Pineapple'] = 5; My goal is to create permutation pairs using th ...

Array contains a copy of an object

The outcome I am striving for is: dataset: [ dataset: [ { seriesname: "", data: [ { value: "123", }, { value: &q ...

use php code to dynamically populate a select dropdown element with jquery

Here's my query: Array ( [0] => Array ( [idCustomer] => 2553 [session] => [noMobil] => 666 [keterangan] => Sistem [tahun] => 2012 [merk] => Sist ...

Why do we use array[] instead of just array when creating a new stdClass object?

$arr = []; $arr[] = new stdClass; //this adds an object to the array $arr = new stdClass; //this changes arr into an object It's peculiar because $arr was initially declared as an array. If you remove the brackets in $arr = new stdClass; then $arr ...

Breaking up an array in PHP according to search outcomes

My dataset consists of a multidimensional array generated from a MySQL query that aggregates results by various groups and sums. The array details costtotal and hitcount for different variations of 'ad_type', 'click_status', and 'l ...

I currently have an array of strings and wish to print only the lines that include a specific substring

Here i want to showcase lines that contain the following strings: Object.< anonymous > These are multiple lines: Discover those lines that have the substring Object . < anonymous > Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'you ...

Determining the size of each element in an array using Angular

Can someone help me figure out how to count the number of times "Jack" appears as the winner in my array? I need to return this count. function myCtrl($scope) { $scope.data = [{ game: 1, dnscore: 10, bwscore: 9, winner ...

Mastering the Art of Concise Writing: Tips to

Is there a way to write more concisely, maybe even in a single line? this.xxx = smt.filter(item => item.Id === this.smtStatus.ONE); this.yyy = smt.filter(item => item.Id === this.smtStatus.TWO); this.zzz = smt.filter(item => item.Id == ...

Checking the dimensions and information of a JSON collection - a step-by-step guide

Recently, I've encountered a JSON String that was returned with an array inside in my Java SpringBoot application. {... "downlineLevels": ["01","02","03","04","05","06","07"] } Unfortunately, only the following JUnit tests have passed. 1) .andExpec ...

Echo the date while using the foreach function to list arrays together

Is there a way to sort articles by Date instead of just Name? Directory structure: Blog/2019/articleDirA, Blog/2019/articleDirB,... Blog/2018/articleDirA, Blog/2018/articleDirB,... Each article directory (ex. articleB) contains these files: data.php ...

Quickly remove items from a list without any keywords from the given keywords list

This spreadsheet contains two sheets named "RemoveRecords" and "KeywordsList". I need to use app scripts to remove any records that are not included in the "KeywordsList" sheet. This should be done by searching through the "ArticleLink" column. Although ...

Generate a flexible JSON array in VB.NET

Looking to generate a flexible array that can be converted into a JSON array for visualization with Morris charts. The usual approach in VB.NET is as follows: Dim xArray(2) xArray(0) = New With {Key .TradingDay = "Day1", .Seller1 = 1500, .Seller2 = 160 ...

Utilize VueJS to bind a flat array to a v-model through the selection of multiple checkboxes

My Vue component includes checkboxes that have an array of items as their value: <div v-for="group in groups"> <input type="checkbox" v-model="selected" :value="group"> <template v-for="item in group"> <input type ...

Improving Javascript Arrays for Easier Reading

A dataset has been organized into a table format as shown below: +------+---------+----+----+----+----+-------+----------+ | Year | Subject | A | B | C | F | Total | PassRate | +------+---------+----+----+----+----+-------+----------+ | 2015 | Maths ...