J
J
jizzy2020-04-23 21:14:30
JavaScript
jizzy, 2020-04-23 21:14:30

JavaScript. How to remove two different elements from an array?

const arr = [
  { "Name": "Alex", "sex":"man","age":50,"workplace":"office"},
  {"Name": "Katya", "sex":"woman","age":33,"workplace":"office"},
  {"Name": "Igor", "sex":"man","age":22,"workplace":"park"},
  {"Name": "Olga", "sex":"woman","age":19,"workplace":"park"},
  {"Name": "Maks", "sex":"man","age":40,"workplace":"hotel"}
];

let arr2 = [];

for(let prop in arr){
  if(arr[prop].workplace == "office"){
    arr2.push(arr[prop]);
  }
}

console.log(arr2);

I need to display not only objects with office, but to also display hotel, how to do this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-04-23
@jizzy

arr.filter(n => [ 'office', 'hotel' ].includes(n.workplace))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question