Organizing various response data in an array-type JavaScript variable

Seeking assistance please.. I have successfully created a function to retrieve all supplier data from the database. However, I now want to create javascript variables in array format to store this information. For example - one array for supplier_id and another for supplier_name.

function LoadSuppliers() {  
    $.ajax({
        type: 'GET',
        url: '/supplier/getSupplier',
        success: function(response) {
            console.log(response);   
        
        }, 
        error: function(data) {
            console.log('something went wrong!');
        }
    });
}

https://i.sstatic.net/k8wBr.jpg

Answer №1

Assuming I understood the question correctly, to convert the properties into an array you can utilize the map function.

Here is an example:

let supplierIds = response.results.map(function (item) { return item.supplier_id; });

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Encountering a 500 error in production when making a call to the Next.js API

I have a dedicated API folder within my next.js application to handle server-side endpoints: import { NextApiRequest, NextApiResponse } from 'next' import Cors from 'cors' // Setting up the CORS middleware const cors = Cors({ method ...

Refresh the copyright year by syncing with a time server

Not long ago, I found myself needing to update the copyright year on a website. Instead of using JavaScript to get the year from the system time, I began wondering if there was a way to utilize an internet time server for this purpose. I believe that util ...

Whenever I attempt to connect to Stripe, my code fails to execute properly

My knowledge of Javascript is limited, but I have a basic understanding. I am currently diving into learning about Stripe and testing it in a local environment with a Wordpress install. Following the Stripe documentation, I have successfully installed Node ...

Exploring the depths of angular views with the powerful ui.router

Can someone guide me on how to implement login in the index and info in login using ui.router in Angular? I want to display different views based on the URL being used. For instance, when logging in and accessing the driver view, I want the HTML to be inj ...

The 404 error is handled by the express application before continuing to other routes. Some routes may not be recognized by the express.Router module

Shown below is the content of app.js: var express = require('express'); var routes = require('./routes/index'); app = express(); app.use('/', routes); // catch 404 and forward to error handler app.use(function(req, res, next ...

What is the correct way to invoke a function from the reducer/actions within this specific scenario?

There seems to be an issue with the action/reducer I am attempting to call. It appears that the function is not being read correctly when called. The problem lies within the deleteWorkout function. I've attempted to use mapDispatchToProps and have al ...

Numerous perspectives of the TradingView Widget

I am facing an issue with the real-time chart component from tradingview.com. The chart is rendering twice at the start and every time I make a change in my code, it renders again. This results in multiple renders as shown in the image below. If anyone k ...

Proper way to save blob information in MySQL with Node.js and JavaScript

I am dealing with an array of integers ranging from 0 to 255 in javascript; var arr = [249, 13, 105, 170]; The task at hand is to save this data in a mysql database while following a specific rule: 1 number = 1 byte Therefore, if the array length is 4 ...

Ways to integrate a security protocol with a graphql resolver

I'm currently diving into the world of graphql and I'm facing a challenge with incorporating an authentication/authorization system into my project. I stumbled upon an example on Medium, but I'm struggling to grasp how a guard connects with ...

Ever-changing CSS class attribute?

One challenge I'm facing involves a navigation bar with elements rendered using the Struts2 iterator tag. Here is an example: <ul> <li><a href="#">Home</a></li> <s:iterator var="row" value="#session.PrivMenu.chil ...

Utilizing the Squared² Symbol in the Jscript File Path for Execution

I am encountering an issue with launching applications on a corporate portal that are tied to a specific business group. The problem arises when trying to access a file path that includes a ² character. This software is widely used on over 3000 computers ...

How to handle javascript and json file processing?

My json data structure is as follows: var json = { "A": { "A1": { "A11": "A", "A12": "B", "A13": "C" }, "A2": { "A21": ...

Toggling dropdown menus with conditional Jquery statements

I am experiencing some discomfort. :) I've been working on a calorie calculator that includes a dropdown for various dietary preferences. Currently, when a user clicks the button, the dropdown appears and disappears when clicking outside the button. ...

Error message C2057 occurred when a constant expression was expected to be used, but a

It seems like I'm facing a bit of a challenge here. const int nfft = 256 * 1024; const float samplefrequency = 256.0 * 1024.0 ; // Hz /* The buffer, spectral and data arrays for the FFT */ kiss_fft_cfg mybuff; kiss_fft_cpx samples[nfft]; kiss_fft_c ...

Passing a null value to the server through jQuery AJAX is not possible. Instead, the server receives the string "null" as the value

Recently, I've been working on updating a javascript/php/ajax application to incorporate jQuery so that it can function smoothly across all browsers, not just Firefox. However, I've hit a snag when trying to pass true, false, and null values usi ...

Which Client-Side JavaScript Frameworks Pair Seamlessly With Node.js, Express.js, and socket.io.js?

Currently, I am in the process of developing a web application utilizing Node.js, Express.js, and socket.io.js on the server side. Are there any front-end frameworks (such as Agility, Angular, Backbone, Closure, Dojo, Ember, GWT, jQuery, Knockback, Knocko ...

"Always receive the latest version of the file with every request in Node.js

Essentially, I have developed a server that responds to user requests by sending a JS file in object format. This JS file is generated using two configuration files named config1.js and config2.js. Below is my code snippet: var express = require('ex ...

Organizing data in a table with AngularJS

I have recently started learning AngularJS and am currently working on sorting my table by clicking on the table headers. When a header is clicked, I want the rows to be sorted based on that specific header. If you'd like to see my code in action, he ...

MVC3: Easily browse through tables by accessing details directly from the details view, eliminating the need to click on

I am currently working on an Index view where a table displays a list of items, each with a link to show its details in another partialview loaded through Ajax. Users have expressed interest in being able to easily navigate between "Next Item" and "Previo ...

Display the children in the JSON array using PHP

I'm having trouble extracting the [steamid] from a JSON array. I keep receiving an error message that says: "Notice: Undefined index: friends". I attempted to iterate through the array and display only the steamids, but it seems like I am not correctl ...