Comments (6)
When you compare to a value, you can use either _.matchesProperty
shorthand or matches
shorthand.
The former (and what you asked in the first question) requires an array with a pair of path to value.
The latter requires an object (like the docs for _.matches
What you're trying to use is the _.property
shorthand, which does not require an array.
That is:
filteredArray = _.filter(fooArray, 'bar[0]'); // output: [{bar: ["foostring"], num: 1}]
Hope this helps!
from eslint-plugin-lodash.
The path in Method 2 is incorrect. Your path foo.bar[0]
is looking for object.foo.bar[0]
.
You just want:
fooArray = _.filter(fooArray, ['bar[0]', true]);
from eslint-plugin-lodash.
What @jdalton said is correct. The rule works fine.
from eslint-plugin-lodash.
Thanks @jdalton. Works fine now. π
from eslint-plugin-lodash.
@jdalton now assuming below object. Is there any way to check for truthy (string) values? sorry I didn't see any example of this kind in doc so posting here.
let fooArray;
fooArray = [{
bar: ["foostring"],
num: 1
}, {
bar: [false],
num: 2
}];
I want to check if string is present or not. below example returns empty array in this case.
filterdArray = _.filter(fooArray, ['bar[0]']); // output: []
from eslint-plugin-lodash.
Thanks @ganimomer for the clarification. That really helped.
from eslint-plugin-lodash.
Related Issues (20)
- `prop-shorthand` does not report on `_.orderBy` HOT 1
- Dependabot couldn't reach repo.dev.wixpress.com/artifactory/api/npm/npm-repos as it timed out
- `collection-ordering`: Require same number of iteratees and orders
- Error when typing `_()`
- chaining rule doesnβt work when chain is imported from lodash/chain HOT 1
- Can I autofix by `preferred-alias` rule? HOT 1
- `path-style` rule has bug
- False positive for prefer-lodash-chain with _.range? HOT 1
- Version 7.1.0 is failing on the project with Lodash v3 HOT 1
- prefer-noop shouldn't trigger if a function has comment inside
- path-style is supposed to be "as-needed" by default
- bug: lodash/prefer-lodash-method false positive with nextjs (react) router replace
- path-style rule auto-fix incorrectly formats object accessor causing regressions! HOT 1
- Whitesource scan vulnerability on lodash < 4.19.19
- Support ESLint 8.x HOT 1
- Recommending `_.split` for v3 despite it not existing
- type import produces false positive under lodash/import-scope HOT 1
- `prefer-is-undefined` and `prefer-is-null`
- Combine rules for `import-scope`, accept both 'member' and 'method' HOT 2
- lodash/prefer-* rules cause problems with Jest mocks HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eslint-plugin-lodash.