0

I have an array of objects, something like this example:

var b = [
  {
    'super_attribute[170]': "41", 
    'super_attribute[171]': "15",
    'data': 1
  },
  {
    'super_attribute[150]': "401", 
    'super_attribute[181]': "5",
    'test': 1234
  }
];

I want to select the object out of the array that has the attribute and value values from a

var a = {
  'super_attribute[170]': "41", 
  'super_attribute[171]': "15"
};

Is this possible with array filters or mapping?

1

1 Answer 1

2
var filtered = b.filter(function(item){

return item.attribute == 'something' && item.value == 1;

});

edit: here you'll find the documentation to filter

Sign up to request clarification or add additional context in comments.

2 Comments

I just edited my original question with the updated code that I should have posted in the first place. The issue is that I the values in the object a will change
if the values in a change then don't compare like @Manish suggested with static values - rather compare with the right key from a: item.attribute == a.attribute ... ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.