How to compare two array and get the first matching object from the first array? [closed]











up vote
0
down vote

favorite















var arr1 =['Five','Four','Full','Straight','Three','Two','One','Bust']
var arr2 = [{player1-box: "One"},{player2-box: "One"},{player3-box: "Four"},{player1-box: "Three"},{player2-box: "Three"},{player3-box: "Two"},{player1-box: "Five"},{player2-box: "One"},{player3-box: "One"}]





I have two array as described above.
My requirement is to compare two arrays and get the first matching value from the second array.
Here in this example value 'FIVE' from arr1 will match the values into the 7th index into the second array arr2



Means I will get the key and value like {player1-box: "Five"} ?
could someone look into this and let me know ?



Thanks..










share|improve this question













closed as off-topic by Code-Apprentice, Cindy Meister, Billal Begueradj, Devon_C_Miller, PRMoureu Nov 12 at 6:37


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Code-Apprentice, Billal Begueradj, Devon_C_Miller, PRMoureu

If this question can be reworded to fit the rules in the help center, please edit the question.













  • Use a for loop or forEach().
    – Code-Apprentice
    Nov 11 at 18:05












  • Why that arr2 ? why not just { player1-box: "value", player2-box: "value" } or [{ name: "player1", value: "value" }, /*...*/] ?
    – Jonas Wilms
    Nov 11 at 18:05








  • 1




    You can't have dashes in the object keys.
    – Yaakov Ainspan
    Nov 11 at 18:06















up vote
0
down vote

favorite















var arr1 =['Five','Four','Full','Straight','Three','Two','One','Bust']
var arr2 = [{player1-box: "One"},{player2-box: "One"},{player3-box: "Four"},{player1-box: "Three"},{player2-box: "Three"},{player3-box: "Two"},{player1-box: "Five"},{player2-box: "One"},{player3-box: "One"}]





I have two array as described above.
My requirement is to compare two arrays and get the first matching value from the second array.
Here in this example value 'FIVE' from arr1 will match the values into the 7th index into the second array arr2



Means I will get the key and value like {player1-box: "Five"} ?
could someone look into this and let me know ?



Thanks..










share|improve this question













closed as off-topic by Code-Apprentice, Cindy Meister, Billal Begueradj, Devon_C_Miller, PRMoureu Nov 12 at 6:37


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Code-Apprentice, Billal Begueradj, Devon_C_Miller, PRMoureu

If this question can be reworded to fit the rules in the help center, please edit the question.













  • Use a for loop or forEach().
    – Code-Apprentice
    Nov 11 at 18:05












  • Why that arr2 ? why not just { player1-box: "value", player2-box: "value" } or [{ name: "player1", value: "value" }, /*...*/] ?
    – Jonas Wilms
    Nov 11 at 18:05








  • 1




    You can't have dashes in the object keys.
    – Yaakov Ainspan
    Nov 11 at 18:06













up vote
0
down vote

favorite









up vote
0
down vote

favorite














var arr1 =['Five','Four','Full','Straight','Three','Two','One','Bust']
var arr2 = [{player1-box: "One"},{player2-box: "One"},{player3-box: "Four"},{player1-box: "Three"},{player2-box: "Three"},{player3-box: "Two"},{player1-box: "Five"},{player2-box: "One"},{player3-box: "One"}]





I have two array as described above.
My requirement is to compare two arrays and get the first matching value from the second array.
Here in this example value 'FIVE' from arr1 will match the values into the 7th index into the second array arr2



Means I will get the key and value like {player1-box: "Five"} ?
could someone look into this and let me know ?



Thanks..










share|improve this question
















var arr1 =['Five','Four','Full','Straight','Three','Two','One','Bust']
var arr2 = [{player1-box: "One"},{player2-box: "One"},{player3-box: "Four"},{player1-box: "Three"},{player2-box: "Three"},{player3-box: "Two"},{player1-box: "Five"},{player2-box: "One"},{player3-box: "One"}]





I have two array as described above.
My requirement is to compare two arrays and get the first matching value from the second array.
Here in this example value 'FIVE' from arr1 will match the values into the 7th index into the second array arr2



Means I will get the key and value like {player1-box: "Five"} ?
could someone look into this and let me know ?



Thanks..






var arr1 =['Five','Four','Full','Straight','Three','Two','One','Bust']
var arr2 = [{player1-box: "One"},{player2-box: "One"},{player3-box: "Four"},{player1-box: "Three"},{player2-box: "Three"},{player3-box: "Two"},{player1-box: "Five"},{player2-box: "One"},{player3-box: "One"}]





var arr1 =['Five','Four','Full','Straight','Three','Two','One','Bust']
var arr2 = [{player1-box: "One"},{player2-box: "One"},{player3-box: "Four"},{player1-box: "Three"},{player2-box: "Three"},{player3-box: "Two"},{player1-box: "Five"},{player2-box: "One"},{player3-box: "One"}]






javascript arrays






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 11 at 18:03









Sachin

102




102




closed as off-topic by Code-Apprentice, Cindy Meister, Billal Begueradj, Devon_C_Miller, PRMoureu Nov 12 at 6:37


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Code-Apprentice, Billal Begueradj, Devon_C_Miller, PRMoureu

If this question can be reworded to fit the rules in the help center, please edit the question.




closed as off-topic by Code-Apprentice, Cindy Meister, Billal Begueradj, Devon_C_Miller, PRMoureu Nov 12 at 6:37


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Code-Apprentice, Billal Begueradj, Devon_C_Miller, PRMoureu

If this question can be reworded to fit the rules in the help center, please edit the question.












  • Use a for loop or forEach().
    – Code-Apprentice
    Nov 11 at 18:05












  • Why that arr2 ? why not just { player1-box: "value", player2-box: "value" } or [{ name: "player1", value: "value" }, /*...*/] ?
    – Jonas Wilms
    Nov 11 at 18:05








  • 1




    You can't have dashes in the object keys.
    – Yaakov Ainspan
    Nov 11 at 18:06


















  • Use a for loop or forEach().
    – Code-Apprentice
    Nov 11 at 18:05












  • Why that arr2 ? why not just { player1-box: "value", player2-box: "value" } or [{ name: "player1", value: "value" }, /*...*/] ?
    – Jonas Wilms
    Nov 11 at 18:05








  • 1




    You can't have dashes in the object keys.
    – Yaakov Ainspan
    Nov 11 at 18:06
















Use a for loop or forEach().
– Code-Apprentice
Nov 11 at 18:05






Use a for loop or forEach().
– Code-Apprentice
Nov 11 at 18:05














Why that arr2 ? why not just { player1-box: "value", player2-box: "value" } or [{ name: "player1", value: "value" }, /*...*/] ?
– Jonas Wilms
Nov 11 at 18:05






Why that arr2 ? why not just { player1-box: "value", player2-box: "value" } or [{ name: "player1", value: "value" }, /*...*/] ?
– Jonas Wilms
Nov 11 at 18:05






1




1




You can't have dashes in the object keys.
– Yaakov Ainspan
Nov 11 at 18:06




You can't have dashes in the object keys.
– Yaakov Ainspan
Nov 11 at 18:06












2 Answers
2






active

oldest

votes

















up vote
1
down vote



accepted










I don't see any way with the current data setup other than iterating over arr1. This will either return the first found in arr1 of undefined if none are found.






var arr1 =['Five','Four','Full','Straight','Three','Two','One','Bust']
var arr2 = [{'player1-box': "One"},{'player2-box': "One"},{'player3-box': "Four"},{'player1-box': "Three"},{'player2-box': "Three"},{'player3-box': "Two"},{'player1-box': "Five"},{'player2-box': "One"},{'player3-box': "One"}]

function findFirst(keys, players){
for (key of keys){
let player = players.find(player => Object.values(player).includes(key))
if (player) return player
}
}
let first = findFirst(arr1, arr2)
console.log(first)





If there's the possibility of a tie, you could use filter() instead of find() and return an array:






var arr1 =['Five','Four','Full','Straight','Three','Two','One','Bust']
var arr2 = [{'player1-box': "One"},{'player2-box': "Five"},{'player3-box': "Four"},{'player1-box': "Three"},{'player2-box': "Three"},{'player3-box': "Two"},{'player1-box': "Five"},{'player2-box': "One"},{'player3-box': "One"}]

function findFirst(keys, players){
for (key of keys){
let player = players.filter(player => Object.values(player).includes(key))
if (player) return player
}
}
console.log(findFirst(arr1, arr2))








share|improve this answer




























    up vote
    3
    down vote













    You could iterate arr1 with Array#some and exit the loop if an object is found in arr2 with Array#find.



    While the objects have different keys, you need to get the values for checking.






    var arr1 = ['Five', 'Four', 'Full', 'Straight', 'Three', 'Two', 'One', 'Bust'],
    arr2 = [{ "player1-box": "One" }, { "player2-box": "One" }, { "player3-box": "Four" }, { "player1-box": "Three" }, { "player2-box": "Three" }, { "player3-box": "Two" }, { "player1-box": "Five" }, { "player2-box": "One" }, { "player3-box": "One" }],
    result;

    arr1.some(v => result = arr2.find(o => Object.values(o).includes(v)));
    console.log(result);





    Without arrow functions and ES6 parts.






    var arr1 = ['Five', 'Four', 'Full', 'Straight', 'Three', 'Two', 'One', 'Bust'],
    arr2 = [{ "player1-box": "One" }, { "player2-box": "One" }, { "player3-box": "Four" }, { "player1-box": "Three" }, { "player2-box": "Three" }, { "player3-box": "Two" }, { "player1-box": "Five" }, { "player2-box": "One" }, { "player3-box": "One" }],
    result;

    arr1.some(function (v) {
    return arr2.some(function (o) {
    if (Object.keys(o).some(function (k) { return v === o[k]; })) {
    return result = o;
    }
    });
    });
    console.log(result);








    share|improve this answer























    • Thanks, could you please send it without arrow operator ?
      – Sachin
      Nov 11 at 18:25


















    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote



    accepted










    I don't see any way with the current data setup other than iterating over arr1. This will either return the first found in arr1 of undefined if none are found.






    var arr1 =['Five','Four','Full','Straight','Three','Two','One','Bust']
    var arr2 = [{'player1-box': "One"},{'player2-box': "One"},{'player3-box': "Four"},{'player1-box': "Three"},{'player2-box': "Three"},{'player3-box': "Two"},{'player1-box': "Five"},{'player2-box': "One"},{'player3-box': "One"}]

    function findFirst(keys, players){
    for (key of keys){
    let player = players.find(player => Object.values(player).includes(key))
    if (player) return player
    }
    }
    let first = findFirst(arr1, arr2)
    console.log(first)





    If there's the possibility of a tie, you could use filter() instead of find() and return an array:






    var arr1 =['Five','Four','Full','Straight','Three','Two','One','Bust']
    var arr2 = [{'player1-box': "One"},{'player2-box': "Five"},{'player3-box': "Four"},{'player1-box': "Three"},{'player2-box': "Three"},{'player3-box': "Two"},{'player1-box': "Five"},{'player2-box': "One"},{'player3-box': "One"}]

    function findFirst(keys, players){
    for (key of keys){
    let player = players.filter(player => Object.values(player).includes(key))
    if (player) return player
    }
    }
    console.log(findFirst(arr1, arr2))








    share|improve this answer

























      up vote
      1
      down vote



      accepted










      I don't see any way with the current data setup other than iterating over arr1. This will either return the first found in arr1 of undefined if none are found.






      var arr1 =['Five','Four','Full','Straight','Three','Two','One','Bust']
      var arr2 = [{'player1-box': "One"},{'player2-box': "One"},{'player3-box': "Four"},{'player1-box': "Three"},{'player2-box': "Three"},{'player3-box': "Two"},{'player1-box': "Five"},{'player2-box': "One"},{'player3-box': "One"}]

      function findFirst(keys, players){
      for (key of keys){
      let player = players.find(player => Object.values(player).includes(key))
      if (player) return player
      }
      }
      let first = findFirst(arr1, arr2)
      console.log(first)





      If there's the possibility of a tie, you could use filter() instead of find() and return an array:






      var arr1 =['Five','Four','Full','Straight','Three','Two','One','Bust']
      var arr2 = [{'player1-box': "One"},{'player2-box': "Five"},{'player3-box': "Four"},{'player1-box': "Three"},{'player2-box': "Three"},{'player3-box': "Two"},{'player1-box': "Five"},{'player2-box': "One"},{'player3-box': "One"}]

      function findFirst(keys, players){
      for (key of keys){
      let player = players.filter(player => Object.values(player).includes(key))
      if (player) return player
      }
      }
      console.log(findFirst(arr1, arr2))








      share|improve this answer























        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted






        I don't see any way with the current data setup other than iterating over arr1. This will either return the first found in arr1 of undefined if none are found.






        var arr1 =['Five','Four','Full','Straight','Three','Two','One','Bust']
        var arr2 = [{'player1-box': "One"},{'player2-box': "One"},{'player3-box': "Four"},{'player1-box': "Three"},{'player2-box': "Three"},{'player3-box': "Two"},{'player1-box': "Five"},{'player2-box': "One"},{'player3-box': "One"}]

        function findFirst(keys, players){
        for (key of keys){
        let player = players.find(player => Object.values(player).includes(key))
        if (player) return player
        }
        }
        let first = findFirst(arr1, arr2)
        console.log(first)





        If there's the possibility of a tie, you could use filter() instead of find() and return an array:






        var arr1 =['Five','Four','Full','Straight','Three','Two','One','Bust']
        var arr2 = [{'player1-box': "One"},{'player2-box': "Five"},{'player3-box': "Four"},{'player1-box': "Three"},{'player2-box': "Three"},{'player3-box': "Two"},{'player1-box': "Five"},{'player2-box': "One"},{'player3-box': "One"}]

        function findFirst(keys, players){
        for (key of keys){
        let player = players.filter(player => Object.values(player).includes(key))
        if (player) return player
        }
        }
        console.log(findFirst(arr1, arr2))








        share|improve this answer












        I don't see any way with the current data setup other than iterating over arr1. This will either return the first found in arr1 of undefined if none are found.






        var arr1 =['Five','Four','Full','Straight','Three','Two','One','Bust']
        var arr2 = [{'player1-box': "One"},{'player2-box': "One"},{'player3-box': "Four"},{'player1-box': "Three"},{'player2-box': "Three"},{'player3-box': "Two"},{'player1-box': "Five"},{'player2-box': "One"},{'player3-box': "One"}]

        function findFirst(keys, players){
        for (key of keys){
        let player = players.find(player => Object.values(player).includes(key))
        if (player) return player
        }
        }
        let first = findFirst(arr1, arr2)
        console.log(first)





        If there's the possibility of a tie, you could use filter() instead of find() and return an array:






        var arr1 =['Five','Four','Full','Straight','Three','Two','One','Bust']
        var arr2 = [{'player1-box': "One"},{'player2-box': "Five"},{'player3-box': "Four"},{'player1-box': "Three"},{'player2-box': "Three"},{'player3-box': "Two"},{'player1-box': "Five"},{'player2-box': "One"},{'player3-box': "One"}]

        function findFirst(keys, players){
        for (key of keys){
        let player = players.filter(player => Object.values(player).includes(key))
        if (player) return player
        }
        }
        console.log(findFirst(arr1, arr2))








        var arr1 =['Five','Four','Full','Straight','Three','Two','One','Bust']
        var arr2 = [{'player1-box': "One"},{'player2-box': "One"},{'player3-box': "Four"},{'player1-box': "Three"},{'player2-box': "Three"},{'player3-box': "Two"},{'player1-box': "Five"},{'player2-box': "One"},{'player3-box': "One"}]

        function findFirst(keys, players){
        for (key of keys){
        let player = players.find(player => Object.values(player).includes(key))
        if (player) return player
        }
        }
        let first = findFirst(arr1, arr2)
        console.log(first)





        var arr1 =['Five','Four','Full','Straight','Three','Two','One','Bust']
        var arr2 = [{'player1-box': "One"},{'player2-box': "One"},{'player3-box': "Four"},{'player1-box': "Three"},{'player2-box': "Three"},{'player3-box': "Two"},{'player1-box': "Five"},{'player2-box': "One"},{'player3-box': "One"}]

        function findFirst(keys, players){
        for (key of keys){
        let player = players.find(player => Object.values(player).includes(key))
        if (player) return player
        }
        }
        let first = findFirst(arr1, arr2)
        console.log(first)





        var arr1 =['Five','Four','Full','Straight','Three','Two','One','Bust']
        var arr2 = [{'player1-box': "One"},{'player2-box': "Five"},{'player3-box': "Four"},{'player1-box': "Three"},{'player2-box': "Three"},{'player3-box': "Two"},{'player1-box': "Five"},{'player2-box': "One"},{'player3-box': "One"}]

        function findFirst(keys, players){
        for (key of keys){
        let player = players.filter(player => Object.values(player).includes(key))
        if (player) return player
        }
        }
        console.log(findFirst(arr1, arr2))





        var arr1 =['Five','Four','Full','Straight','Three','Two','One','Bust']
        var arr2 = [{'player1-box': "One"},{'player2-box': "Five"},{'player3-box': "Four"},{'player1-box': "Three"},{'player2-box': "Three"},{'player3-box': "Two"},{'player1-box': "Five"},{'player2-box': "One"},{'player3-box': "One"}]

        function findFirst(keys, players){
        for (key of keys){
        let player = players.filter(player => Object.values(player).includes(key))
        if (player) return player
        }
        }
        console.log(findFirst(arr1, arr2))






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 11 at 18:14









        Mark Meyer

        32k32651




        32k32651
























            up vote
            3
            down vote













            You could iterate arr1 with Array#some and exit the loop if an object is found in arr2 with Array#find.



            While the objects have different keys, you need to get the values for checking.






            var arr1 = ['Five', 'Four', 'Full', 'Straight', 'Three', 'Two', 'One', 'Bust'],
            arr2 = [{ "player1-box": "One" }, { "player2-box": "One" }, { "player3-box": "Four" }, { "player1-box": "Three" }, { "player2-box": "Three" }, { "player3-box": "Two" }, { "player1-box": "Five" }, { "player2-box": "One" }, { "player3-box": "One" }],
            result;

            arr1.some(v => result = arr2.find(o => Object.values(o).includes(v)));
            console.log(result);





            Without arrow functions and ES6 parts.






            var arr1 = ['Five', 'Four', 'Full', 'Straight', 'Three', 'Two', 'One', 'Bust'],
            arr2 = [{ "player1-box": "One" }, { "player2-box": "One" }, { "player3-box": "Four" }, { "player1-box": "Three" }, { "player2-box": "Three" }, { "player3-box": "Two" }, { "player1-box": "Five" }, { "player2-box": "One" }, { "player3-box": "One" }],
            result;

            arr1.some(function (v) {
            return arr2.some(function (o) {
            if (Object.keys(o).some(function (k) { return v === o[k]; })) {
            return result = o;
            }
            });
            });
            console.log(result);








            share|improve this answer























            • Thanks, could you please send it without arrow operator ?
              – Sachin
              Nov 11 at 18:25















            up vote
            3
            down vote













            You could iterate arr1 with Array#some and exit the loop if an object is found in arr2 with Array#find.



            While the objects have different keys, you need to get the values for checking.






            var arr1 = ['Five', 'Four', 'Full', 'Straight', 'Three', 'Two', 'One', 'Bust'],
            arr2 = [{ "player1-box": "One" }, { "player2-box": "One" }, { "player3-box": "Four" }, { "player1-box": "Three" }, { "player2-box": "Three" }, { "player3-box": "Two" }, { "player1-box": "Five" }, { "player2-box": "One" }, { "player3-box": "One" }],
            result;

            arr1.some(v => result = arr2.find(o => Object.values(o).includes(v)));
            console.log(result);





            Without arrow functions and ES6 parts.






            var arr1 = ['Five', 'Four', 'Full', 'Straight', 'Three', 'Two', 'One', 'Bust'],
            arr2 = [{ "player1-box": "One" }, { "player2-box": "One" }, { "player3-box": "Four" }, { "player1-box": "Three" }, { "player2-box": "Three" }, { "player3-box": "Two" }, { "player1-box": "Five" }, { "player2-box": "One" }, { "player3-box": "One" }],
            result;

            arr1.some(function (v) {
            return arr2.some(function (o) {
            if (Object.keys(o).some(function (k) { return v === o[k]; })) {
            return result = o;
            }
            });
            });
            console.log(result);








            share|improve this answer























            • Thanks, could you please send it without arrow operator ?
              – Sachin
              Nov 11 at 18:25













            up vote
            3
            down vote










            up vote
            3
            down vote









            You could iterate arr1 with Array#some and exit the loop if an object is found in arr2 with Array#find.



            While the objects have different keys, you need to get the values for checking.






            var arr1 = ['Five', 'Four', 'Full', 'Straight', 'Three', 'Two', 'One', 'Bust'],
            arr2 = [{ "player1-box": "One" }, { "player2-box": "One" }, { "player3-box": "Four" }, { "player1-box": "Three" }, { "player2-box": "Three" }, { "player3-box": "Two" }, { "player1-box": "Five" }, { "player2-box": "One" }, { "player3-box": "One" }],
            result;

            arr1.some(v => result = arr2.find(o => Object.values(o).includes(v)));
            console.log(result);





            Without arrow functions and ES6 parts.






            var arr1 = ['Five', 'Four', 'Full', 'Straight', 'Three', 'Two', 'One', 'Bust'],
            arr2 = [{ "player1-box": "One" }, { "player2-box": "One" }, { "player3-box": "Four" }, { "player1-box": "Three" }, { "player2-box": "Three" }, { "player3-box": "Two" }, { "player1-box": "Five" }, { "player2-box": "One" }, { "player3-box": "One" }],
            result;

            arr1.some(function (v) {
            return arr2.some(function (o) {
            if (Object.keys(o).some(function (k) { return v === o[k]; })) {
            return result = o;
            }
            });
            });
            console.log(result);








            share|improve this answer














            You could iterate arr1 with Array#some and exit the loop if an object is found in arr2 with Array#find.



            While the objects have different keys, you need to get the values for checking.






            var arr1 = ['Five', 'Four', 'Full', 'Straight', 'Three', 'Two', 'One', 'Bust'],
            arr2 = [{ "player1-box": "One" }, { "player2-box": "One" }, { "player3-box": "Four" }, { "player1-box": "Three" }, { "player2-box": "Three" }, { "player3-box": "Two" }, { "player1-box": "Five" }, { "player2-box": "One" }, { "player3-box": "One" }],
            result;

            arr1.some(v => result = arr2.find(o => Object.values(o).includes(v)));
            console.log(result);





            Without arrow functions and ES6 parts.






            var arr1 = ['Five', 'Four', 'Full', 'Straight', 'Three', 'Two', 'One', 'Bust'],
            arr2 = [{ "player1-box": "One" }, { "player2-box": "One" }, { "player3-box": "Four" }, { "player1-box": "Three" }, { "player2-box": "Three" }, { "player3-box": "Two" }, { "player1-box": "Five" }, { "player2-box": "One" }, { "player3-box": "One" }],
            result;

            arr1.some(function (v) {
            return arr2.some(function (o) {
            if (Object.keys(o).some(function (k) { return v === o[k]; })) {
            return result = o;
            }
            });
            });
            console.log(result);








            var arr1 = ['Five', 'Four', 'Full', 'Straight', 'Three', 'Two', 'One', 'Bust'],
            arr2 = [{ "player1-box": "One" }, { "player2-box": "One" }, { "player3-box": "Four" }, { "player1-box": "Three" }, { "player2-box": "Three" }, { "player3-box": "Two" }, { "player1-box": "Five" }, { "player2-box": "One" }, { "player3-box": "One" }],
            result;

            arr1.some(v => result = arr2.find(o => Object.values(o).includes(v)));
            console.log(result);





            var arr1 = ['Five', 'Four', 'Full', 'Straight', 'Three', 'Two', 'One', 'Bust'],
            arr2 = [{ "player1-box": "One" }, { "player2-box": "One" }, { "player3-box": "Four" }, { "player1-box": "Three" }, { "player2-box": "Three" }, { "player3-box": "Two" }, { "player1-box": "Five" }, { "player2-box": "One" }, { "player3-box": "One" }],
            result;

            arr1.some(v => result = arr2.find(o => Object.values(o).includes(v)));
            console.log(result);





            var arr1 = ['Five', 'Four', 'Full', 'Straight', 'Three', 'Two', 'One', 'Bust'],
            arr2 = [{ "player1-box": "One" }, { "player2-box": "One" }, { "player3-box": "Four" }, { "player1-box": "Three" }, { "player2-box": "Three" }, { "player3-box": "Two" }, { "player1-box": "Five" }, { "player2-box": "One" }, { "player3-box": "One" }],
            result;

            arr1.some(function (v) {
            return arr2.some(function (o) {
            if (Object.keys(o).some(function (k) { return v === o[k]; })) {
            return result = o;
            }
            });
            });
            console.log(result);





            var arr1 = ['Five', 'Four', 'Full', 'Straight', 'Three', 'Two', 'One', 'Bust'],
            arr2 = [{ "player1-box": "One" }, { "player2-box": "One" }, { "player3-box": "Four" }, { "player1-box": "Three" }, { "player2-box": "Three" }, { "player3-box": "Two" }, { "player1-box": "Five" }, { "player2-box": "One" }, { "player3-box": "One" }],
            result;

            arr1.some(function (v) {
            return arr2.some(function (o) {
            if (Object.keys(o).some(function (k) { return v === o[k]; })) {
            return result = o;
            }
            });
            });
            console.log(result);






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 11 at 18:34

























            answered Nov 11 at 18:12









            Nina Scholz

            172k1384147




            172k1384147












            • Thanks, could you please send it without arrow operator ?
              – Sachin
              Nov 11 at 18:25


















            • Thanks, could you please send it without arrow operator ?
              – Sachin
              Nov 11 at 18:25
















            Thanks, could you please send it without arrow operator ?
            – Sachin
            Nov 11 at 18:25




            Thanks, could you please send it without arrow operator ?
            – Sachin
            Nov 11 at 18:25



            Popular posts from this blog

            Bressuire

            Vorschmack

            Quarantine