H
H
Hastes12342020-04-26 12:42:28
JavaScript
Hastes1234, 2020-04-26 12:42:28

How to filter objects in an array by a word in a key string?

Hello. There is an array with objects. How to filter (remove) unnecessary objects using .filter if the status value contains the word "maybe"? Thank you!

[
{ city: "Moscow",
number: 123,
status: "maybe ok"
} , 
{ city: "Moscow",
number: 123,
status: "ok"
},
{ city: "Moscow",
number: 123,
status: "maybe"
},
]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2020-04-26
@Hastes1234

arr.filter(n => !~n.status.indexOf("maybe"))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question