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.
Asked
Active
Viewed 46 times
0
-
You have answered yourself ... for loop. Google javascript for loop and you will get plenty of examples – Guanxi May 05 '15 at 09:38
-
You do not show any efford that you've tryed to search over internet. http://stackoverflow.com/questions/9882284/looping-through-array-and-removing-items-without-breaking-for-loop – Marin Takanov May 05 '15 at 09:39
3 Answers
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 -

Community
- 1
- 1
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;
}
}

KBN
- 2,915
- 16
- 27
-
I can't use splice or pop.... array sequence is changing,,, could you please suggest anything other than using splice or pop function. – CodeMachine May 05 '15 at 09: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 May 05 '15 at 09: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]);
}
}

Guruprasad J Rao
- 29,410
- 14
- 101
- 200
-
I can't use splice or pop.... array sequence is changing,,, could you please suggest anything other than using splice or pop function. – CodeMachine May 05 '15 at 09:56
-