Extract the comma-separated values from an array that are combined as one

please take a look at this dropdown

In my array list displayed as ng-option, some values come as PCBUs separated by commas. For example, in the JSON response, the value of the first PCBU is "NKSMO,NNOWR". I am attempting to display these as two separate PCBU options: "NKSMO" and "NNOWR" in the ng-option, instead of one combined option.

JSON Response

"statusType":"success",
"statusMsg":{  
    "approvals":{  
         "inProgress":[  
            {  
               "projectStatus":"Pending Decision",
               "pcbu":"NKSMO,NNOWR",
               "statusUpdatedDate":"2019-07-31 15:04:30",
               "requestType":"PORCHNGEREQ",
               "folderStatus":false,
               "projectName":"TEST POR CAHNGE REQ",
               "priority":"NORMAL",
               "projectId":24324
            },
            {  
               "projectStatus":"Pending Decision",
               "pcbu":"NKSMO",
               "statusUpdatedDate":"2019-05-24 09:41:36",
               "requestType":"PORCHNGEREQ",
               "folderStatus":false,
               "projectName":"Mobile Test - Jack - POR 1",
               "priority":"NORMAL",
               "projectId":23351
            }
         ],
$scope.pcbuSelect = "";

$scope.loadRequests=function(requestType){
    var jsonObj = {
      "userId":$scope.userId,
      "requestType":requestType
    };
    workflowProjFundFactory.getApprovalRequest(jsonObj)
    .success(function(data, status) {
        if (JSON.stringify(data.statusType).indexOf("success") > -1) {            
            var allrequests = data.statusMsg;
            $scope.inProgressDataList=$scope.inProgressDataList
                .concat(allrequests.approvals.inProgress) ;
            $scope.pcbuList = $scope.inProgressDataList
                .concat(allrequests.approvals.pcbu);
        }
    }
}
<label for="PCBU" class="control-label-left typeAllOptionStyling">PCBU</label>
<div class="selecteddiv" style="margin-right: 1%;">
    <select ng-model="pcbuSelect" name="pcbuSelect"
            ng-options="removeUndefined(item.pcbu) for item in pcbuList | unique:'pcbu'"></select>
</div>

I have attempted to use the split method to separate the comma in the array, but it has not been successful for me.

Answer №1

Sorry if I misunderstood your question, but I've gathered all PCBU (comma separated) values into a single array that can easily be used with ng-options.

let json={
    "statusType": "success",
    "statusMsg": {    
    "approvals": {
        "inProgress": [{
                "projectStatus": "Pending Decision",
                "pcbu": "NKSMO,NNOWR",
                "statusUpdatedDate": "2019-07-31 15:04:30",
                "requestType": "PORCHNGEREQ",
                "folderStatus": false,
                "projectName": "TEST POR CAHNGE REQ",
                "priority": "NORMAL",
                "projectId": 24324

             },
             {
                "projectStatus": "Pending Decision",
        "pcbu": "NKSMO",
                "statusUpdatedDate": "2019-05-24 09:41:36",
                "requestType": "PORCHNGEREQ",
                "folderStatus": false,
                "projectName": "Mobile Test - Jack - POR 1",
                "priority": "NORMAL",
                "projectId": 23351
             }
            ]
        }
    }
}

let dropdown=(json.statusMsg.approvals.inProgress.map(p=>p.pcbu.split(",")).flat());
let unique_dd=[...new Set(dropdown)]; 
console.log(unique_dd);

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

What is the best way to send form data to MongoDB using React?

I am seeking guidance on how to pass the values of form inputs to my MongoDB database. I am unsure of the process and need assistance. From what I understand, in the post request within my express route where a new Bounty is instantiated, I believe I need ...

Strategies for transferring data between multiple controllers

Hello, I am just starting to learn AngularJS and have a basic understanding of controllers, which help transfer data to the view. Here is a sample controller based on what I know: angular.module('marksTotal',[]).controller('totalMarks&apos ...

Load image in browser for future display in case of server disconnection

Incorporating AngularJS with HTML5 Server-Side Events (SSE) has allowed me to continuously update the data displayed on a webpage. One challenge I've encountered is managing the icon that represents the connection state to the server. My approach inv ...

Is it considered a best practice to utilize JavaScript for positioning elements on a

I recently started learning JavaScript and jQuery, and I've been using them to position elements on my website based on screen and window size. It's been really helpful, but I'm starting to wonder if it's a good practice since it makes ...

Obtain the complete shipping address with the 'addressLines' included using Apple Pay

Currently working on integrating Apple Pay WEB using JS and Braintree as the payment provider. In order to calculate US sales tax for the order, I need to gather certain information. The user initiates the payment process by clicking on the "Pay with Appl ...

Is it possible for me to rearrange the sequence of Apple, Banana, Mango, Pineapple, and Kiwi?

arrange() organizes the elements in a custom order: var fruits = new Array("Apple", "Banana", "Kiwi", "Ananas", "Mango"); Namen.arrange(); document.write(fruits); I don't want them alphabetically sort ...

Enhancing IntelliJ IDEA's autocomplete functionality with JavaScript libraries

Is there a way to add my custom JavaScript library to IntelliJ IDEA 10.5 or 11 for autocomplete functionality? I want to specify that IDEA should recognize and suggest auto-completions for objects from my library. While it sometimes works automatically, ...

Can inner function calls be mimicked?

Consider this scenario where a module is defined as follows: // utils.ts function innerFunction() { return 28; } function testing() { return innerFunction(); } export {testing} To write a unit test for the testing function and mock the return value ...

The array value has not been initialized and needs to be set before further

I have an array called @Lst_1, and one of the elements is 0. Whenever I try to access that specific element, as shown in the example below, the value stored in the second index of the array is 0. $Log_Sheet->write(Row,0,"$Lst_1[2]",$Format); However, ...

Utilizing jQuery to target a select element's two specific children

I am trying to target the parent element by matching two specific children elements. Here is my code: $('span:contains("11:00am"), span.name:contains("Tom")').parents("a").css("background-color","rgb(255, 255, 255)"); <script src="https://c ...

How to retrieve a variable from a Multidimensional JSON decoded array?

I am currently attempting to determine which type of card the customer used for their transaction. To do this, I am testing the following code snippet: $request_body = '{"id":8799347,"order_id":"1854059","accepted":true,"type":"Payment","text_on_stat ...

The transformation of elements within a C array may appear peculiar

I've encountered a strange issue with my code. Sometimes when I print arr[4], the value is 0, but other times it's 2. It's puzzling! #include <stdio.h> #include <string.h> int countBalls(int, int); void main() { int res; ...

What is the best way to deselect the first radio button while selecting the second one, and vice versa, when there are two separate radio groups?

I am looking to achieve a functionality where if the first radio button is selected, I should receive the value true and the second radio button should be unselected with the value false. Similarly, if the second radio button is selected, I should receive ...

Tips for showing a success notification once a PHP script has been successfully completed on a form

Hey everyone, I need some help with a PHP script that I have connected to a single input form. I'm looking to create a success page for users after they submit their email, with a link back. This seems simple enough, but I'm still learning PHP. ...

Ways to retrieve information from a URL using the .get() method in a secure HTTPS connection

As I work on handling user input from a form using node.js, express, and bodyParser, I encounter an issue. Even after using console.log(req.body), the output is {}. This is puzzling as there is data in the URL when the form is submitted successfully at htt ...

Error: XYZ has already been declared in a higher scope in Typescript setInterval

I've come across an interesting issue where I'm creating a handler function and trying to set the current ref to the state's value plus 1: const useTimer = () => { const [seconds, setSeconds] = useState(0); const counterRef = useRef(n ...

Tips for initiating and terminating the evaluation of a condition at regular intervals using JavaScript

I'm currently working on a JavaScript application where I need to achieve the following: Periodically check every 5 seconds to see if there is an element with the 'video' tag on the page. Once an element with the 'video' tag ...

Is it possible to drag the div container in HTML to resize its width from both left to right and right to left?

After posing my initial inquiry, I have devised a resizing function that allows for the expansion of a div's width. When pulling the right edge of the div to resize its width from left to right, is it possible to adjust the direction or how to resize ...

Whenever my code is used within Google Sites, it triggers the opening of a new and empty tab

When using this code inside an HTML box in Google Sites, a problem arises. It seems to work perfectly fine in Internet Explorer and Chrome when saved to an HTML file. However, within Google Sites, it unexpectedly opens a new tab with no data. The code st ...

How can you search through an array of objects in Mongo without relying on RHS as a reference?

Here is a snapshot of the Mongo Collection: { "_id" : ObjectId("5b693cbc032ee2fbb1d097f9"), "name" : "PersonName1", "email" : "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="96f2f0f1f2f0f1d6f1fbf7ff ...