logo
Tags down

shadow

How to merge new data to old array?


By : medik
Date : October 15 2020, 08:10 AM
I wish did fix the issue. I have a array like this. Here I have included only 5 fields but in real I have around 45 fieldname. , You can do like that
code :
var temp = [{id:1, product_name: 'aaa', val1:1, val2:2, val3:4},
{id:2, product_name: 'bbb', val1:1, val2:2, val3:4},
{id:3, product_name: 'ccc', val1:1, val2:2, val3:4},
{id:4, product_name: 'ddd', val1:1, val2:2, val3:4}];

temp = temp.map(row => {
  const newRow = row;
  let total = 0;

  total = parseInt(row['val1']) +
    parseInt(row['val2']) +
    parseInt(row['val3']);

  newRow['total'] = total;

  newRow['val1'] = row['val1'] + '%';
  newRow['val2'] = row['val2'] + '%';
  newRow['val3'] = row['val3'] + '%';

  return newRow;
});
$("#result").append(JSON.stringify(temp) + "<br />");
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id='result'>

</div>


Share : facebook icon twitter icon

How do I merge data into Multidimentional array based on a value in current/previous array


By : Benjamin Bytheway
Date : March 29 2020, 07:55 AM
I wish did fix the issue. If you are trying to separate out each call based on answered in separate instances, PLUS you want to count same named src differently based on each instance, this will break your array down into sections based on spans of time (well, not real time, just the array key differences). Note, you can break this down one more time to just isolate each instance of total if you want:
code :
$calls = array(
                0 => array('calldate' => '2014-12-01 08:31:47', 'src' => '1234', 'duration' => 30 ),
                1 => array('calldate' => '2014-12-01 08:32:22', 'src' => '1234', 'duration' => 30 ),
                2 => array('calldate' => '2014-12-01 08:32:57', 'src' => '1234', 'duration' => 30 ), 
                3 => array('calldate' => '2014-12-01 08:33:32', 'src' => '1234', 'duration' => 30 ), 
                4 => array('calldate' => '2014-12-01 08:34:07', 'src' => '1234', 'duration' => 30 ), 
                5 => array('calldate' => '2014-12-01 08:34:42', 'src' => '1234', 'duration' => 30 ), 
                6 => array('calldate' => '2014-12-01 08:35:12', 'src' => '1234', 'duration' => 10 ), 
                7 => array('calldate' => '2014-12-01 08:35:47', 'src' => '1234', 'duration' => 30 ), 
                8 => array('calldate' => '2014-12-01 08:36:22', 'src' => '1234', 'duration' => 30 ), 
                9 => array('calldate' => '2014-12-01 08:51:20', 'src' => '5678', 'duration' => 15 ), 
                10 => array('calldate' => '2014-12-01 09:09:14', 'src' => '5678', 'duration' => 10 ), 
                11 => array('calldate' => '2014-12-01 09:22:58', 'src' => '9123', 'duration' => 12 ), 
                12 => array('calldate' => '2014-12-01 09:42:42', 'src' => '4567', 'duration' => 30 ), 
                13 => array('calldate' => '2014-12-01 09:43:17', 'src' => '4567', 'duration' => 30 ), 
                14 => array('calldate' => '2014-12-01 09:43:52', 'src' => '4567', 'duration' => 30 ), 
                15 => array('calldate' => '2014-12-01 09:44:27', 'src' => '4567', 'duration' => 30 ), 
                16 => array('calldate' => '2014-12-01 09:45:02', 'src' => '4567', 'duration' => 29 ), 
                17 => array('calldate' => '2014-12-01 09:55:31', 'src' => '9123', 'duration' => 15 ), 
                18 => array('calldate' => '2014-12-01 10:34:29', 'src' => '8912', 'duration' => 10 ), 
                19 => array('calldate' => '2014-12-01 13:26:29', 'src' => '3456', 'duration' => 30 ), 
                20 => array('calldate' => '2014-12-01 13:27:04', 'src' => '3456', 'duration' => 30 ), 
                21 => array('calldate' => '2014-12-01 13:27:39', 'src' => '3456', 'duration' => 30 ), 
                22 => array('calldate' => '2014-12-01 13:28:14', 'src' => '3456', 'duration' => 30 ), 
                23 => array('calldate' => '2014-12-01 13:28:49', 'src' => '3456', 'duration' => 30 ), 
                24 => array('calldate' => '2014-12-01 13:29:24', 'src' => '3456', 'duration' => 30 ), 
                25 => array('calldate' => '2014-12-01 13:29:54', 'src' => '3456', 'duration' => 4 ),
                26 => array('calldate' => '2014-12-01 13:29:54', 'src' => '1234', 'duration' => 30 )
            );
$i = 0;
foreach($calls as $row) {

        $user[$row['src']][$i]['calls'][]   =   $row['duration'];
        $user[$row['src']][$i]['duration']  =   array_sum($user[$row['src']][$i]['calls']);

        if($row['duration'] < 30) {
                $i++;
            }
    }

echo '<pre>';
print_r($user);
Array
(
    [1234] => Array
        (
            [0] => Array
                (
                    [calls] => Array
                        (
                            [0] => 30
                            [1] => 30
                            [2] => 30
                            [3] => 30
                            [4] => 30
                            [5] => 30
                            [6] => 10
                        )

                    [duration] => 190
                )

            [1] => Array
                (
                    [calls] => Array
                        (
                            [0] => 30
                            [1] => 30
                        )

                    [duration] => 60
                )

            [5] => Array
                (
                    [calls] => Array
                        (
                            [0] => 30
                        )

                    [duration] => 30
                )

        )

    [5678] => Array
        (
            [1] => Array
                (
                    [calls] => Array
                        (
                            [0] => 15
                            [1] => 10
                        )

                    [duration] => 25
                )

        )

    [9123] => Array
        (
            [2] => Array
                (
                    [calls] => Array
                        (
                            [0] => 12
                        )

                    [duration] => 12
                )

            [3] => Array
                (
                    [calls] => Array
                        (
                            [0] => 15
                        )

                    [duration] => 15
                )

        )

    [4567] => Array
        (
            [3] => Array
                (
                    [calls] => Array
                        (
                            [0] => 30
                            [1] => 30
                            [2] => 30
                            [3] => 30
                            [4] => 29
                        )

                    [duration] => 149
                )

        )

    [8912] => Array
        (
            [3] => Array
                (
                    [calls] => Array
                        (
                            [0] => 10
                        )

                    [duration] => 10
                )

        )

    [3456] => Array
        (
            [4] => Array
                (
                    [calls] => Array
                        (
                            [0] => 30
                            [1] => 30
                            [2] => 30
                            [3] => 30
                            [4] => 30
                            [5] => 30
                            [6] => 4
                        )

                    [duration] => 184
                )

        )

)

Merge multidimentional array if parent id same then merge child data


By : Susan_Y
Date : March 29 2020, 07:55 AM
like below fixes the issue Loop over your input array using foreach, adding the PMST data to an output array as you go. It looks like it's safe to assume the PMSP data for two tasks on the same project will be the same.
code :
$output = [];
foreach ($input as $task) {
    if (!isset($output[$task["PMSP"]["id"]])) {
        $output[$task["PMSP"]["id"]] = ["PMSP" => $task["PMSP"], "taskdetails" => []];
    }
    $output[$task["PMSP"]["id"]]["taskdetails"][] = $task["PMST"];
}

what is the data type that i want to use when merging Array when i merge String array and Integer Array into merge Array


By : Jfy001
Date : March 29 2020, 07:55 AM
may help you . In Java, String and Integer both are inherited from Object. So you can use Object type to define a general array.
code :
    String[] strArray = { "a", "b", "c" };
    Integer[] intArray = { 1, 2, 3 };
    Object[] arr = new Object[strArray.length + intArray.length];
    int j = 0;
    for (int i = 0; i < strArray.length; i++) {
        arr[j++] = strArray[i];
    }
    for (int i = 0; i < intArray.length; i++) {
        arr[j++] = intArray[i];
    }

I have two array in my o/p. one is result array and the other is data array how to merge both array's into a single arra


By : user903166
Date : March 29 2020, 07:55 AM
around this issue how to merge both arrays into a single array matching the first array coordinates with second array's originToDestinedpointDirectionUrl lat and long?
code :
let op = {
        "result": [
            {
                "id": "2X56cPnr0mvS9Cq8MAW1jQ",
                "alias": "the-hot-tomato-fruita",
                "name": "The Hot Tomato",
                "coordinates": {
                    "latitude": 39.1594399,
                    "longitude": -108.732141
                }
            },
            {
                "id": "bGNVfuaRoIpPdUKsfROfZQ",
                "alias": "camillas-kaffe-fruita",
                "name": "Camilla's Kaffe",
                "coordinates": {
                    "latitude": 39.1588374652023,
                    "longitude": -108.732291567344
                }
            },
            {
                "id": "jZtuJxbKfS8s4QCe_TrTxw",
                "alias": "colorado-national-monument-fruita",
                "name": "Colorado National Monument",
                "coordinates": {
                    "latitude": 39.097564,
                    "longitude": -108.7387526
                }
          }

    ],
    "data": [
    {
                "originToDestinedpointDirectionUrl": "https://www.google.com/maps/dir/Los Angeles, CA, USA/39.097564,-108.7387526"
    },
    {
                "originToDestinedpointDirectionUrl": "https://www.google.com/maps/dir/Los Angeles, CA, USA/39.1594399,-108.732141"
     },
     {
                "originToDestinedpointDirectionUrl": "https://www.google.com/maps/dir/Los Angeles, CA, USA/39.1588374652023,-108.732291567344"
 		 }
] };

let resultArr = op.result;
let dataArr = op.data;

let thirdArray = [];

dataArr.forEach(data => {
  let splittedArr = data.originToDestinedpointDirectionUrl.split("/");
  let coordinate = splittedArr[splittedArr.length-1].split(",");

  let corLat = coordinate[0];
  let corLong = coordinate[1];

  resultArr.forEach(res => {

    if(res.coordinates.latitude == corLat && res.coordinates.longitude == corLong){
      thirdArray.push({ "id": res.id, "alias": res.alias, "name": res.name, "coordinates": res.coordinates, "originToDestinedpointDirectionUrl": data })
    }
  });
});

console.log(thirdArray);

Comparing two array objects data and merge as one object into array in javascript?


By : user1793505
Date : March 29 2020, 07:55 AM
hop of those help? my arrays : , You can use .map() and Object.assign() methods:
code :
const create = [{"month":"Jan","createCount":"4"}, {"month":"Feb","createCount":"5"}],
      close = [{"month":"Jan","closeCount":"3"}, {"month":"Feb","closeCount":"5"}];

const result = create.map(
    o => Object.assign({}, o, close.find(({month}) => month === o.month))
);

console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0; }
Related Posts Related Posts :
  • How to get a subarray?
  • Javascript JSON woes
  • Use Jquery animate to have a button move a box to the next corner
  • Why is this JavaScript not interpreted as a code block when semi-colon is used?
  • Reload another page when I click on button
  • Should functions that call a callback function be bound?
  • For loop print in single line separated by spaces - JS
  • Add Javascript Variable into asp-route-data
  • Two different POST requests are making use of the same variable
  • Convert JSOn object into a flat JSON Array
  • Manually adding to an HTML range input gives unexpected results
  • Refreshing component after making api call Reactjs
  • Google App Script : Finding The Last Blank Row
  • I cant for the life of me figure out whats wrong with this script
  • Order divs by ID in Javascript
  • set new element class property value
  • How to pass a java variable to a different jsp page containing javascript?
  • Locked it method in chai
  • React JS : history.push is not a function error and it isn't navigating to a different page onclick of swal
  • How can i set timeout for localstorage for Angular 2+?
  • Must use destructuring props assignment
  • Jest Compared values have no visual difference. when testing arrays
  • Uncaught Error: #90211 ExtensionName Error - Node.JS, Heroku, JavaScript App using FusionCharts
  • Is it possible in firebase auth to update user and custom claims at the same time node?
  • Filter out capitalized letters
  • Yet Another Google Firebase Error "Function returned undefined, expected Promise or value"
  • How do I address method in a Vue.js component from inside callback function?
  • What is the name of this feature in JavaScript?
  • Vue js using scope-slot and trying to use a property from within but having no visibility
  • Dynamic javascript table won't display iterations from array
  • How to start/end smoke.js animation by clicking a nav button?
  • Map array of strings as object properties
  • Appending new inputs with JS wipes previous ones
  • Chai Request With URL instead of JS File
  • React Jest Async Tests
  • Unordered list bullet not showing at an expected location
  • How to create an array from an object?
  • How to get prefix name from html tag
  • javascript - Simulate a click event (tap with finger) on a button in iOS
  • How to get the value of checkboxes in a kendo grid
  • Uncaught TypeError: Object(...) is not a function at eval (global-styles.js)
  • Generate divs on scroll bottom
  • App deployed to Cloud Foundry fails to start
  • Show label and percentage in Google pie chart
  • Warn user before leaving web page if changes haven't been saved
  • Objects are not valid as a React child getting error when adding div?
  • why is callback not working in nodejs with mysql?
  • D3 v4 date ticks never display last item
  • How to assign a variable which function takes as a parameter
  • Javascript how hidden div onclick of phrase
  • Can I set state inside a useEffect hook
  • How can I draw a line to the highest datapoint in chart js?
  • Make <a> link activate expand text button
  • Django: fastest way to update the data that was once sent from template to view
  • JavaScript Scope of Vaadin's "AbstractJavaScriptComponent"
  • Firestore cloud functions summing subcollections values
  • d3.js in vue component - How to hook mouse events to elements?
  • Can't add href and class to list item through javascript
  • Jest - checking local storage is called in an async function that is being mocked
  • How do I print only the selection from my list group item?
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org