I have list of account Ids in an array and list of accounts in array.

I need to find the account Ids from the account list and want to change the status field.

var accId=[]; //holding accIds
var accObjectMap = [];
var accList=component.get("v.listOfacc");
for(var i=0; i<accList.length; i++) {
    var temp = { "key": accList[i].Id, "list": [accList[i]] };

 for(var j=0;j<accId.length;j++){


Eg : My accId have 2 account ids .My accList have 6 values. I want to find that 2 values from acclist and assign the status as "New".


You can use Array.prototype.filter, Array.prototype.indexOf, and Array.prototype.forEach:

var accIds = []; // Has account Ids
var accountList = component.get("v.listOfacc");
var accountsToUpdate = accountList.filter(item => accIds.indexOf(item.Id) > -1);
accountsToUpdate.forEach(item => item.Status__c = "New");

filter accepts a method that returns true/false for each item and returns an Array for each item where the value is true. indexOf finds a matching value in an Array or returns -1. forEach takes each item in an Array and passes it to a method; we use this to update the status of each account.

| improve this answer | |
  • Thanks .The account status got updated. But the list holds only that 2 records .I want to display all the 6 records with the 2 updated value records. – jessy Mar 20 '19 at 10:47
  • @jessy It wasn't clear that was what you were trying to do in your original question. You'd want to set the original list back in to your attribute (component.set("v.listOfacc", accountList);). – sfdcfox Mar 20 '19 at 11:00
  • yes . I am iterating the list "v.listOfacc" in aura :iteration .I have a pick list option for status field. whenever i select value it will apply to account records and display the accounts with updated status. – jessy Mar 20 '19 at 11:34
  • @jessy Did you get your problem solved? If not, anything else I can do? – sfdcfox Mar 20 '19 at 12:35
  • my problem got resolved .Thanks for you help – jessy Mar 20 '19 at 13:00

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.