0

If the array position is not fixed, then how we remove the array ? I mean not using index/position. May be by using for loop. Position of the array is not fixed.

2
  • You have answered yourself ... for loop. Google javascript for loop and you will get plenty of examples
    – Guanxi
    Commented May 5, 2015 at 9:38
  • You do not show any efford that you've tryed to search over internet. stackoverflow.com/questions/9882284/… Commented May 5, 2015 at 9:39

3 Answers 3

2

This sounds like a duplicate, if you want to remove an item from an array, in the loop you need to do check on if say the BankBranchId == 6, if it is the you want to remove the object from the array.

Which is shown here -

Remove Object from Array using JavaScript

0

Use splice to remove elements from an array, how to determine what is to be deleted. I think your BankBranchId is unique, so here it goes.

var removeBBID = 6;
for(key in bankBranchReponse) {
  if(bankBranchReponse[key].BankBranchId == removeBBID) {
    bankBranchReponse.splice(key, 1);
    break;
  }
}
2
  • I can't use splice or pop.... array sequence is changing,,, could you please suggest anything other than using splice or pop function. Commented May 5, 2015 at 9:55
  • @AtDesk, I'm confused, you need not know the index of the object you want to remove. removeBBID is the BankBranchId value, within the object.
    – KBN
    Commented May 5, 2015 at 9:57
0

I agree with the link what @JessicPartridge has given as her answer and what and @KBN has mentioned in his answer but there checking is happening on only one value of array!! Below code checks all the value and then removes array object from list!

for(var i=0;i<bankBranchReponse.length;i++)
{
    if(bankBranchReponse[i].BankBranchId === removeVariable.BankBranchId && 
       bankBranchReponse[i].BankBranchName===removeVariable.BankBranchName &&
       bankBranchReponse[i].isPaymentMade===removeVariable.isPaymentMade)
    {
                        bankBranchReponse.pop(bankBranchReponse[i]);
    }
}

DEMO HERE

2
  • I can't use splice or pop.... array sequence is changing,,, could you please suggest anything other than using splice or pop function. Commented May 5, 2015 at 9:56
  • changing in the sense!! Could you explain how?? Commented May 5, 2015 at 10:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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