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.

Achieving a Compact Structure for a Hierarchical JSON Data

I'm in search of a technique that can linearize a "json" hash into a compressed hash while retaining the path details within the compressed keys. For instance: h = {"a" => "foo", "b" => [{"c" => "bar", "d" => ["baz"]}]} The desired outcome fo ...

Enhance the appearance of a multidimensional array using main and sub-main styling

Struggling with a new challenge here... after spending hours trying to wrap my head around it, I'm still stuck. Let's dive in... I've worked with arrays before, but only simple ones like this: $arr = array('1', '2', '3',[...]); I could handle that kind o ...

Understanding the time complexity of Object.entries()

Is the complexity of Object.entries() in JavaScript known? According to information from this question, it seems like it could possibly be O(n) if implemented by collecting keys and values as arrays and then combining them together? ...

Delete an item from an array when a dropdown selection is made

When dealing with Angular 8, I encountered a logic issue. There are two drop-down menus: First Drop-down The options in the first menu are populated from an array of objects Example Code, ts: {rs_id: "a5f100d5-bc88-4456-b507-1161575f8819", ...

Use JavaScript to upload a JSON file containing arrays into separate tabs

Looking for help with incorporating JSON data into an HTML template that features tabs and a gallery? Take a look at my setup below: <div class="tab"> <button class="tabLinks" onclick="openDiv(event, 'overview'); appendData()" id="defaultOp ...

Navigating a JSON Array in PHP: A Step-by-Step Guide

I'm working with a JSON array that looks like this: { "people":[ { "id": "8080", "content": "foo" }, { "id": "8097", "content": "bar" } ] } My question is, how can I search for the ID "8097" and retrieve its c ...

PANDAS: Transforming arrays into individual numbers in a list

My list is printing out as [array([7], dtype=int64), array([11], dtype=int64), array([15, 19, 23, 27, 31, 35, 39, 43, 47, 51, 55, 59, 63, 67], dtype=int64)] However, I want it to look like [7, 11, 15, 19, 23, ...] The issue arises when using pandas ...

Is there a way to efficiently resize a collection of 2D arrays (stored as a 3D array) using a 2D array in NumPy for vectorized operations?

I have a 3D array consisting of N x N covariance matrices for M channels [M x N x N]. Additionally, I possess a 2D matrix containing scaling factors for each channel at various time points [M x T]. My goal is to generate a 4D array that includes a scaled v ...

Vue.js - display additional items in an array with matching titles

I am working with an array of objects, examples include: [{ title: 'foo' id: 1, name: 'anne' }, { title: 'example', id: 2, name: 'anne' }, { title: 'ex', id: 3, name: 'deb' }] The current display on the page is showca ...

Utilize PHP to filter JSON data and dynamically populate a dropdown menu with the results

In my PHP application, I have a JSON data set containing information about various users. I need to filter out the individuals with a status of Active and display them in a dropdown list. How can I achieve this? Below is the JSON data: [ { "usernam ...

What is the most efficient way to transfer a large search results array between NodeJS and AngularJS?

My application is built with NodeJS for the back-end and AngularJS for the front-end. I've run into an issue where sending a search query from Angular's $http to the back-end results in a bottleneck when there is a slow internet connection. Angular has to ...

Transform a JSON array into an array of objects using typescript

I have a JSON array that I need to convert into an object type array JSON array [ 0:{code: "00125", scheme: "0001", plotNumber: "125", propType: "001", plotType: "001"} 1:{code: "190", scheme: "0001", plotNumber: "NA 190", propType: "001", plotType: "0 ...

"Transforming a query into a JSON array - a step-by-step

My query generates the following output: { key:1,label:"R. Bulan"} { key:2,label:"R. Bintang"} { key:3,label:"R. Akasia"} { key:4,label:"R. Guest Room"} This is my SQL query: select '{ '||'key:'||IDMEETINGROOM||''||',label:"'||NAMARUANG||'"'||'} ' json ...

The interface is unable to populate the Array of Elements

When using Angular, I send a request and save the response in a variable: conversations: Conversation[]; // ChatService getConversations() { return this.http.get<Conversation[]>('/chat/conversations'); } this.chatService.getConversations().sub ...

Mastering the Art of Leveraging Conditionals in JavaScript's Find Function

I'm curious about the implementation of an if statement in the JavaScript find function. My objective is to add the class "filtered-out" to the elements in my cars array when their values do not match. cars.map(car => active_filters.find(x => ...

Formulate a jQuery array consisting of droppable components

I have successfully implemented draggable li-elements and droppable boxes using jQuery UI. Here is my structure: A list of 3 different permission types <ul> <li data-action="create">Create</li> <li data-action="edit">Edi ...

Updating Array Values in AngularJS based on Input Text Box Modifications

In my application, there is a text box that looks like this - <input type="text" class="form-control" id="inputID" name="ItemId" ng-model="inputItemId" ng-required="true" ng-blur="addValueToArray(inputItemId)"/> The user has the ability to add or r ...

Iterating through an array with ngFor to display each item based on its index

I'm working with an ngFor loop that iterates through a list of objects known as configs and displays data for each object. In addition to the configs list, I have an array in my TypeScript file that I want to include in the display. This array always has ...

Create a three-dimensional tree array in Typescript/Javascript by transforming a flat array

Received data is structured as follows: const worldMap = [ { "name": "Germany", "parentId": null, "type": "Country", "value": "country:unique:key:1234", "id&qu ...

Display options through numerical selection

I have been attempting to construct something, but I'm encountering difficulties. My goal is to create a functionality where entering a number in an input field will generate that many additional input fields. I've attempted to implement this using JavaSc ...

How do I convert the object value/data to lowercase in JavaScript using underscore for an HTML5 document?

I am working with an array of objects (arr) where each object consists of 3 properties (Department, Categories, ProductTypes). The values for these properties are a mix of upper and lower case. To perform a comparison between arr and a search filter (alrea ...

Guide on inserting a new column into an array of objects in Vue

Below is the fetch method I have defined to retrieve recordings from the database. However, I need assistance in adding a new column to each record specifically for frontend purposes. Can someone help me with this problem? <script> export default { ...

Compare two arrays for equality in a Vue application

I'm stuck and could use some assistance. I currently have two arrays set up like this: let A = ['a', 'b', 'c'] let B = ['a', 'b', 'c'] I attempted to compare them without success: if(A === B) { console.log('EQUAL') } else { console.log('NOT EQUAL') } ...

Incorporating a data point into a specific column within an array

As a physics undergraduate student with limited computer programming experience, particularly in Python, I am currently working on a script to shift the coordinate system of a set of coordinates from a .xyz file. The goal is to center the coordinate system ...

Add the item to a fresh array using the Ajax function

Here is an array that I have: var arrayOfResults = []; // Results after like statement After making a database call, I receive a JSON result like this: [{ "id": "{fcb42c9c-3617-4048-b2a0-2600775a4c34}", "pid": "{34214CCB-90C3-4D ...

Ways to combine multiple arrays

Here are two arrays: Array1 ( [0] => 1 [1] => 2 [2] => 3 ) Array2 ( [0] => a [1] => b [2] => c ) I would like to create Array3 where: Array3 Like ( [0] => ([0]=>1 [1]=>a) [1] => ([0]=>2 [1 ...

Decoding JSON Data in Angular 2

I am facing a challenge where I have an array of JSON objects that need to be parsed into my Tournament class. The Tournament class has the following structure: export class Tournament { constructor (public id: number, public name: string, ...

Interactively retrieving objects from a JavaScript array based on their keys

let arr = [{id:'one',val:1},{id:'two',val:2}] for( let ii of arr ) { if( ii.hasOwnProperty('id') ) arr[ii.id] = ii } This code snippet allows for accessing the elements in the array by their 'id' key. For exampl ...

What is the best way to convert a series of sentences into JSON format?

I'm struggling with breaking down sentences. Here is a sample of the data: Head to the dining room. Open the cabinet and grab the bottle of whisky. Move to the kitchen. Open the fridge to get some lemonade for Jason. I am looking to format the outcome i ...

The property of undefined map cannot be read

import React from 'react'; import { Card, Text } from "react-native-paper"; import { SafeAreaView, } from "react-native"; class HackerNewsClone extends React.Component { constructor(props) { super(props); this.sta ...

Importing nested JSON arrays into MySQL

I am attempting to insert a JSON array into my MySQL database. Here's the specific structure of the array: ${ "customer_id": "1", "products":[ { "product_id": "1", "product_qty": "2" }, { "product_id": "2", "pro ...

Add a fresh key to a pre-existing array within an object

I have a JSON array that I need to modify by adding a new key. Here is the current structure: stdClass Object ( [set] => Array ( [0] => stdClass Object ( [name] => agenda ...

Is it possible to locate/create a JSON keyname in a jQuery $.post function?

Currently, I am diving back into the world of Ajax after a long break. At this point, I have created a page that is able to fetch a dynamic number of elements (initially ten, but this can change), and populates each of the ten divs with relevant text. In ...

Utilizing v-model for dynamic binding within a v-for iteration

I'm currently working on binding v-model dynamically to an object property within an array of objects. I am unsure about how to accomplish this task. The objective is to choose a user using the Select HTML tag and then display the list of that user&ap ...

Tips for organizing the output of wp_query

I'm looking to organize the results of my wp_query, wanting to arrange them by different parameters without needing to run the query again. Here is what I have so far: $the_query = new WP_Query( $args ); I’d like to sort $the_query; WP_Query gives a st ...

Traversing through each element using Array method

I need to create a redux function that will add a specified number n to the fourth element of an array every time a button is clicked. However, if the element is either L or M, I do not want the addition to occur. For example, starting with this initial a ...

Arranging an array of objects by a specific property in an Angular controller with the help of $filter

In my data set, there is an array of objects referred to as $scope.segments, which looks like this: [ { "_id": "55d1167655745c8d3679cdb5", "job_id": "55d0a6feab0332116d74b253", "status": "available", "sequence": 1, "body_original": " ...

The array element is not being shown in the id "main" when using a for loop with the onchange function

I've been using document.write to display specific content, but it seems to be removing other elements from the page. Is there a way for me to display this loop inside the element with id="main" without losing any content? When I attempt to use document. ...

Printing to the console: the array is empty and contains just one element simultaneously

I've encountered an issue regarding the console.log function that seems related to a specific case I found... JavaScript array length problem Upon checking my console, I noticed this output: https://i.stack.imgur.com/AbCdE.png The code snippet in ...

Dropdown menu of countries created with Material UI

I have been working on creating a dropdown menu in my form that lists all countries. I used an Array of strings with country names and mapped through it to generate the options for the select dropdown. However, the dropdown menu does not seem to be worki ...

Using a function parameter to restore the values of an array

Looking to clear an array using a function parameter. Below is my implementation: <script> fruitArray = ["apple", "banana", "orange", "pineapple"] function clearFruitArray(myArr){ myArr = []; ...

Retrieve characteristics from removed or replicated entities and allocate them to different entities

Looking for a bit of assistance with an array transformation: [ {Code:13938, Country:699, Name:"Crocs", codeProduct:1} {Code:13952, Country:699, Name:"Polo Club", codeProduct:14} {Code:13952, Country:699, Name:"Polo Club", codeProduct:1} {Code ...

Interested in discovering the ins and outs of the JavaScript Map function?

Currently, I am delving into this JavaScript function: function solution (array, commands) { return commands.map (v => { return array.slice(v[0] -1, v[1]).sort((a, b) => a - b).slice(v[2] -1, v[2])[0]; }); } I am puzzled about th ...

Ways to eliminate an item from an array when the value of the object is not present

I am facing an issue with removing objects from an array that do not contain the data object. I have attempted to use the filter method but have not been successful. results.filter(obj => obj.data === undefined) results = [ {id: 1, location: 'a&a ...

Attempting to deserialize serialized data from Django using JSON.parse

I need assistance with some client-side tasks using Javascript. In my view, I serialize a Queryset from my models into JSON and pass it to the template. data = serializers.serialize("json", Profile.objects.filter(user_id=self.request.user)) This results ...

Create a hash by converting arrays into a single array using Ruby mapping

In my programming project, I have an array called dates with 31 items (shown in a shortened form below) Tuesday 8, November Wednesday 9, November #etc. Also, there is a hash named movies with 31 entries, each containing movie names and showtimes (abbrevi ...

Utilizing the json_encode() function in PHP and JSON.parse() method in JavaScript for handling file data interchange

Utilizing json_encode() in PHP to store an array in a file, then leveraging JSON.parse() in JavaScript on the client side to read the json encoded file and pass it as an array to a sorting algorithm: The result of my json_encode() operation in the ...

Transforming HTML code into a structured object

The provided code snippet includes HTML markup that needs to be transformed into a specific format. <html> <head> <title>Hello!</title> </head> <body> <div class=”div1”> <h1>This is a ...

What is the best way to determine the number of dimensions in a JavaScript array?

Take a look at this array and its corresponding expected output: In Javascript, is it possible to dynamically determine how many levels there are in the array ary? var ary = ["a","b",["c","d"],"e",["f","g",["h","i"],"j"]]; Output: 3 var ary = ["a","b",[" ...

In AngularJS, modifying the value of a copied variable will result in the corresponding change in the value of the main

I'm facing a peculiar issue. I have an array of objects and I used angular.forEach to update the price key value of each object. However, when I make changes in each object, it also affects the main array object. Take a look at the code snippet below for ...

Listening for events on an array of elements using jQuery

My task involves populating an array with elements using the .each() method and the $(this) selector. (function($){ var elements = new Array(); var index = 0; $("img").each(function() { if($(this).attr("attribute")){ $(thi ...

Is it possible to fill an array with the children of an element using

Just a quick question for the sake of simplicity... At the moment, my code looks like this: var categoryList = []; $('#share').children().each(function() { categoryList.push($(this).html()); }); I was wondering if there is a more efficient way to po ...

Can you guide me on utilizing filter in an Apps Script array to retrieve solely the row containing a particular user ID within the cell?

I am using an Apps Script that retrieves data from four different columns in a spreadsheet. However, it currently fetches all the rows instead of just the row that matches the randomly generated 8-digit user ID. function doGet(req) { var doc = Spreadshe ...

Obtain a collection of strings from an array of objects based on specified criteria

What is the most efficient method to extract an array of specific strings from an array of objects, where a certain condition needs to be met? Solution Attempt: const array = [{ "Item": "A", "Quantity": 2 ...

"Ionic Calendar 2 - The ultimate tool for organizing your

I am using a calendar in my Ionic app that retrieves events from a database through an API. var xhr = new XMLHttpRequest(); xhr.open('GET', 'http://portalemme2.com.br/SaoJoseAPI/agenda', true); this.http.get('http://portalemme2.c ...

There seems to be an issue with the functionality of Array.filter when trying to use it with arrays

I am facing an issue with filtering branchId from an Array. Here is the code snippet and steps I have taken. const [branchID,setBranchID]=React.useState([]); const tempTwo=[ { branchId: "61b25e0ae177d62ce4cb3b47", bra ...

Transform tree-like JSON array with nested arrays into flat JSON array

I have an array tree in JSON format with potentially unlimited nesting: const namesArrayTree = [ { "name": "Peter" }, { "name": "folder1", "isArray": true, " ...

How can consecutive values be identified in a 3D numpy array in Python without relying on the groupby function?

Consider having a 3D numpy array like the one below: matrices= numpy.array([[[1, 0, 0], #Level 0 [1, 1, 1], [0, 1, 1]], [[0, 1, 0], #Level 1 [1, 1, 0], [0, 0, 0]], [[0, 0, ...

The act of sending back Null from the Array.map() function

I've been attempting to retrieve data from a JavaScript object using the array.map() function. However, the result I'm receiving is null. I'm confused as to what the issue might be. Here's the object: export const Course = [ { course_id: "001-T ...

Innovative approach for showcasing JSON array using checkboxes

I have created a multidimensional array using JSON. However, now I am facing the challenge of organizing groups of checkboxes in a visually appealing manner, such as separating them with horizontal bars or placing them into tables. Here is an example of t ...

python Efficiently load zipfile data into a numpy array

I am searching for a solution to efficiently read a zipfile into memory and extract its contents into a numpy array with numpy datatypes. The challenge lies in the fact that these files are large in size and there are numerous of them, making speed a cruci ...

Transform the output of a MySQL query into a specific JSON format using PHP

My table contains data stored in the following JSON format: https://i.stack.imgur.com/Ab5ug.png The JSON result obtained from a query is as follows: [{ "cnt": "1", "category_name": "Entertainment", "event_name": "Typhoon Sample", "year_o ...

Encountering the error message "Uncaught Error: Objects are not valid as a React child" even though I am not passing objects as children in my React component

My current challenge involves mapping an array of objects, which I retrieved from an axios.get request and then passing them as children to React components. The error message that's causing trouble for me reads as follows: An Error occurred: Objects ...

Retrieve the first two elements from an array and iterate through each of them using a foreach

Currently, I have JSON data formatted like this: https://i.stack.imgur.com/PqOQ0.png I am attempting to create URLs using a foreach loop for an API that requires start and finish dates as parameters. For example, here is a sample URL -> My question is, ...

Show and Arrange Various Key-Object Data pairs

I'm facing a challenge with mapping and displaying a JSON file in a different structure. I need help figuring out how to map the data properly. Here's the JSON file: var data = { "megamenu": [ { "name": "level1.2", "link": "#", ...

convert a JSON object to an array using jQuery

Can anyone help me with converting an object into an array using jQuery? [["20"],["30"],["45"],["54"],["33"],["15"],["54"],["41"]] I am looking to achieve an array output like this: [20,30,45,54,33,15,54,41] Any suggestions on how to accomplish this? ...

Having trouble with adding data from an array of objects to an HTML element using jQuery's each method

I am currently facing an issue with looping through an array of objects using $.each in jQuery and trying to append the values to an <li>. Here is the relevant jQuery code: $(".sidebar").empty().append("<div>" + "<h5>Student Info</ ...

Divide the array of words into segments based on the maximum character limit

I am looking for a way to divide an array of words into chunks based on a maximum number of characters: const maxChar = 50 const arrOfWords =['Emma','Woodhouse,','handsome,','clever,','and','rich,','with','a','comfortable','home','and','happy','dispositio ...

Craving assistance in coding permutations

Thank you for responding. I want to express my gratitude for your efforts in trying to assist me. Unfortunately, I have posted this problem on multiple websites and no one has been willing to help. Regarding my code, my objective is to count permutations. ...

Using Python's for loop to iterate through a two-dimensional index

I'm facing a challenge that seems simple, but I'm struggling to figure out how to tackle it using Python. Within my Python for loop, I have a unique value defined during each iteration. Now, I want to access the value of the NEXT or PREVIOUS unique value ...

How can I make arrays of a specific length and populate them in JavaScript?

For instance: I have over 100 locations in a single array, each with latitude and longitude values. I need to use these locations with the Google distance matrix API to find nearby shops for my users. The issue is that this API can only handle 25 destinat ...

Unraveling a collection of objects containing diverse nested child elements

Displayed below is an instance of the response sent from the server. The list comprises elements with diverse substructures in the info fields. Each element includes 3 fields of the same types, but they have distinct keys. I am unsure how to interpret th ...

Choosing an Array of Integers in PostgreSQL: A Guide

My goal is to extract arrays of integers from a table in this format: [1, 2, 3] I attempted the following query: (SELECT array_to_json(array_agg(row_to_json(s))) FROM( SELECT specialty FROM talent_specialty WHERE userid = 840 )s); This is the result r ...

Using the splice() method to remove an item from an array may cause unexpected results in React applications

Dynamic input fields are being created based on the number of objects in the state array. Each field is accompanied by a button to remove it, but there seems to be unexpected behavior when the button is clicked. A visual demonstration is provided below: ...

Assistance needed: For each loop not iterating properly following variable explosion

I'm struggling to display a row from a database that contains a list of skills as an array delimited by commas. I have provided fully annotated code with an explanation below of what I have done so far. Any help would be greatly appreciated. Thank you ...