You can use array.prototype.every
:
var players = [
{
name: 'Wayne Rooney',
age: 31
},
{
name: 'Lionel Messi',
age: 29
},
{
name: 'Robbie Fowler',
age: 42
}
];
var statePlayers = [
{
name: 'Wayne Rooney',
age: 31
},
{
name: 'Lionel Messi',
age: 29
},
{
name: 'Robbie Fowler',
age: 42
}
];
var equals = players.length === statePlayers.length && players.every((e, i) => e.name === statePlayers[i].name && e.age === statePlayers[i].age);
console.log(equals);