Q:

Division of Array into parts based upon a 2nd Array

Two arrays one with objects and other with string values, based on second arrays values looking to dive first one to multiple. In my case it is two.
    let arr1=  [{"key": "English","code": "en"}, {"key": "Arabic","code": "ar"},
            {"key": "Chinese (traditional)","code": "zh"},
    {"key": "Czech", "code": "cs"},
            {"key": "Dutch","code": "nl"},{"key": "Finnish","code": "fi"}]

let arr2 = ["English", "Dutch", "Finnish"];

let completed =[];
let optional =[];

 for (let i = 0; i < arr2.length; i++) {
                for (let j = 0; j < arr1.length; j++) {
                    if (arr1[j].key === arr1[i]) {
                        completed.push(arr1[j])
                    }else{
                      optional.push(arr1[j])
                    }
                }
            }

Aiming for output like this
completed=[{"key": "English","code": "en"},{"key": "Dutch","code": "nl"},
          {"key": "Finnish","code": "fi"}]

optional=[{"key": "Arabic","code": "ar"},{"key": "Chinese (traditional)","code": "zh"},
        {"key": "Czech", "code": "cs"} ]

A:

Some of the problems with your code are:

Comparing the same array elements if (arr1[j].key === arr1[i]).
Not breaking the loop on finding a matching element and inserting next element immediately into optional array.

Fixing these issues, your code would look like:

let arr1 = [{ "key": "English", "code": "en" }, { "key": "Arabic", "code": "ar" }, { "key": "Chinese (traditional)", "code": "zh" }, { "key": "Czech", "code": "cs" }, { "key": "Dutch", "code": "nl" }, { "key": "Finnish", "code": "fi" } ] ;
let arr2 = ["English", "Dutch", "Finnish"];

let completed = [];
let optional = [];

for (let i = 0; i < arr1.length; i++) {
  let found = false;
  for (let j = 0; j < arr2.length; j++) {
    if (arr1[i].key === arr2[j]) {
      completed.push(arr1[i]);
      found = true;
      break;
    }
  }
  if (!found) {
    optional.push(arr1[i]);
  }
}

console.log("Completed: ", completed);
console.log("Optional: ", optional);

Another easier approach is to use Array.filter() and Array.includes().

let arr1 = [{ "key": "English", "code": "en" }, { "key": "Arabic", "code": "ar" }, { "key": "Chinese (traditional)", "code": "zh" }, { "key": "Czech", "code": "cs" }, { "key": "Dutch", "code": "nl" }, { "key": "Finnish", "code": "fi" } ] ;
let arr2 = ["English", "Dutch", "Finnish"];

let completed = arr1.filter(item => arr2.includes(item.key));
let optional = arr1.filter(item => !arr2.includes(item.key));

console.log("Completed: ", completed);
console.log("Optional: ", optional);

