1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

Fastest way to compare 2 objects in js

Discussão em 'Angular' iniciado por Tenzolinho, Agosto 3, 2025.

  1. Tenzolinho

    Tenzolinho Guest

    Which is the fastest way to compare 2 objects in javascript?

    For example I have these 2 objects:

    a = [{'name': 'john', 'age': 22}, {'name': 'mike', 'age': 23}, {'name': 'anne', 'age': 12}, {'name': 'dan', 'age': 29}, {'name': 'jane', 'age': 34}]
    b = [{'name': 'john', 'age': 22}, {'name': 'anne', 'age': 12}]


    Normally, I would do this:

    for (var i = 0; i < a.length; i++) {
    for (var j = 0; j < b.length; j++) {
    console.log(a) // => [{'name': 'john', 'age': 22}, {'name': 'anne', 'age': 12}]
    }
    }


    This is taking too long, is it there another way faster? Thank you for your time!

    Continue reading...

Compartilhe esta Página