Array compare with for each performance issue

Related searches

I have two arrays with array of objects as follows and one array will have more than 10k records and other have below 100 records

let bigArray = [{id:1, name:"Raj", level:0}, {id:2, name:"sushama", level:2}, {id:3, name:"Sushant", level:0}, {id:4, name:"Bhaskar", level:2},....upto 30k records] 

let smallArray = [{id:2, name:"sushama"}, {id:3, name:"Sushant"}....upto 100 records] 

I want to find where in the index of bigArray in which the object from smallArray resides and add to another array say indexArray I tried below

let indexArray = []; 
bigArray.forEach((element, i) => {
  smallArray.forEach(ele => {
    if ( == && == {
      indexArray.push(i); return;

But it takes time. What would be the fastest approach?

You can turn your O(N^2) approach into an O(N) approach by reducing the bigArray into an object indexed by a key made up from the name and id. Join the name and id by a character that isn't contained in either, such as _:

const indexArray = [];
const bigArrayIndiciesByNameAndId = bigArray.reduce((a, { name, id }, i) => {
  a[name + '_' + id] = i;
  return a;
}, {});

smallArray.forEach(ele => {
  const keyToFind = + '_' +;
  const foundIndex = bigArrayIndiciesByNameAndId[keyToFind];
  if (foundIndex) {

Issue 24700: array compare is hideously slow, It would seem that array's __eq__ is converting every single number into an int, float, etc. first instead of just comparing the arrays in their native� Now, the above works perfectly fine, but I would like to extend the script to check multiple instances of the process at the same time, however I seem to have a little issue with comparing 2 arrays of objects, whereby values from one array are being replaced with the values in the second array.

You could take a Map and map the found indices.

const getKey = ({ id, name }) => [id, name].join('|');

let bigArray = [{ id: 1, name: "Raj", level: 0 }, { id: 2, name: "sushama", level: 2 }, { id: 3, name: "Sushant", level: 0 }, { id: 4, name: "Bhaskar", level: 2 }],
    smallArray = [{ id: 2, name: "sushama" }, { id: 3, name: "Sushant" }],
    map = new Map(, i) => [getKey(o), i]))
    indexArray = => map.get(getKey(o)));


List comparing techniques for faster performance, like an array, where the position of the element is equal to some hash value so for all N < 2^H it's effectively constant), so overall, your matching algorithm� Hi @DesignerMat,. As you could see in your flow, you are update the sharepoint list item for each planner task you have. If you want to update the sharepoint list item with it's corresponding planner task, you should add a Condition inside your Apply to each 2 to acheck if the planner task is the corresponding one with the sharepoint list item.And move your existing Condition to the If yes

return will not "break" the forEach loop. A forEach can't be stopped. The forEach callback function will be called one time per items always. When you find the element, continue running the forEach loop is a waste of resouces.

You should use for instead:

let indexArray = []; 
bigArray.forEach((element, i) => {
    for (var ii = 0; ii < smallArray.length; ii++) {
        var ele = smallArray[ii];
        if ( == && == {
            break; // This will break the "for" loop as we found the item

TIP: Always have a good indentation in your code. Actually your code is really bad indented to identify code blocks at first sight. I fixed it in this example.

JavaScript Array sort: Sorting an Array More Effectively, This tutorial shows you how to use the JavaScript array sort method to sort To fix the issue of sorting the number, you can use the following syntax: to use a custom compare function to convert all elements to the same case e.g., If the number of array elements is increasing, it will potentially decreases the performance. Investigating JavaScript Array Iteration Performance December 13th, 2009 — JavaScript Note: This post is from 2009, and browsers have changed a lot since then. Please don’t use any of this information to make decisions about how to write code.

Performance Tips � The Julia Language, so all the performance issues discussed previously apply. When working with parameterized types, including arrays, it is best to avoid parameterizing It's quite instructive to compare the sheer amount code generated for a simple function Clearly the last two ways are way ahead in terms of performance, while for each statement [type 1] is most expensive operation if compared with other three. Update: Reason for difference in performance. Last two flavors type 3 and 4 have a very little difference and should be considered as same. They both fetch the size of collection initially.

Investigating JavaScript Array Iteration Performance, I wondered how much faster that was than jQuery's $.each, and that got me over an array in JavaScript, so I decided to test them out and compare them But if you're seeing performance problem iterating over large arrays,� If your user-defined function processes each cell in a range, declare the input as a range, assign it to a variant that contains an array, and loop on that. If you want to handle whole column references efficiently, you must make a subset of the input range, dividing it at its intersection with the used range, as in this example.

But there are three types of arrays: 1-dimensional, multidimensional, and jagged arrays. How do they measure up? In this lecture you will learn the difference in performance between the three array types. I will also show you a special technique called 'array flattening', to transform a multidimensional array into a 1-dimensional array.

  • Please give an example output, it is unclear what you want to achieve.
  • Can there be multiple entries with the same id and name in bigArray?
  • No it won't have
  • Cool buddy I will try it
  • Jump target can not cross function error. That is why I tried return