Skip to content

Correct filter example #2602

Open
Open
@johlug

Description

@johlug

for v3 docs

https://vuejs.org/v2/guide/list.html

In this code example

example1.items = example1.items.filter(function (item) {
  return item.message.match(/Foo/)
})

I would write in the return statement

return /Foo/.test(item.message)

Here you just need the test methode. Test methode has a better performance (about 40%, s. https://jsperf.com/test-vs-match-regex).
It's even recommended in the MDN docs, s.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions