0

inputlist

JS controller OUTPUT input of json input json getting out not expected output json

    var lst = JSON.parse(JSON.stringify(component.get('v.lstPetval')));
        var lstInsert = [];
        var lstdel = JSON.parse(JSON.stringify(component.get('v.lstPetDeletedVal')));

        var lstPetUpdateVal = [];
        for(var i=0; i<lst.length; i++) {
            lstInsert.push(lst[i]);
            if(lst[i].objAddOns.hasOwnProperty('Id')) {
                //console.log('lst[i]', lst[i]);
                lstPetUpdateVal.push(lst[i]);

            }
            // if(lst[i].objAddOns.hasOwnProperty('Id')) {
            //  lstInsert.splice(i, 1);
            // }
        }
        console.log('lstInsert', lstInsert);
        for(var i=0; i<lst.length; i++) {
            // console.log('lst[i]123', lst[i]);
            // if(lst[i].objAddOns.hasOwnProperty('Id')) {
            //  console.log('lst[i]', lst[i]);
            //  console.log('lst[i]', lst.indexOf(lst[i]));             
                lstInsert.splice(i, 1);

            // }
            // if(lst[i].objAddOns.hasOwnProperty('Id')) {
            //  
            // }
        }

        if(lstInsert.length == 0){
            lstInsert = null;
        } 
        if(lstdel.length == 0){
            lstdel = null;
        }
        if(lstPetUpdateVal.length == 0){
            lstPetUpdateVal = null;
        }
        console.log('lstInsert',lstInsert,'lstdel',lstdel,'lstPetUpdateVal',lstPetUpdateVal);




[![Here is the screen shot of input and output of JSON][2]][2][![output][2]][2]
  • You have the posted the controller code and console output. what's the error you are facing? – RedDevil Jan 13 '18 at 18:14
  • i getting the error like split function split the value only three index. but my input list has six values – sarvesh kumar Jan 13 '18 at 18:15
0

The reason is splice has three parameters and first one is the index , second one is how many elements to remove and finally items to be added . In your case , you have given only two parameters and the system is removing (0,2,4 indexes from original array) Hence you are seeing only half the values.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.