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 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

Sign up to request clarification or add additional context in comments.

Comments

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 Comments

I can't use splice or pop.... array sequence is changing,,, could you please suggest anything other than using splice or pop function.
@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.
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 Comments

I can't use splice or pop.... array sequence is changing,,, could you please suggest anything other than using splice or pop function.
changing in the sense!! Could you explain how??

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.